akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

const int MAXN = 100000;
vector<int> g[MAXN + 1], path;
int n, sz[MAXN + 1];

void dfs(int v, int p) {
    sz[v]++;
    for(auto u: g[v]) {
        if(u != p) {
            dfs(u, v);
            sz[v] += sz[u];
        }
    }
}

void dfs1(int v, int p) {
    path.push_back(v);
    if(v == n) {
        int pos = ((int)path.size() + 1) / 2;
        if(sz[path[pos]] < n - sz[path[pos]]) {
            cout << "Fennec\n";
            exit(0);
        }
        else {
            cout << "Snuke\n";
            exit(0);
        }
    }
    for(auto u: g[v]) {
        if(u != p) {
            dfs1(u, v);
        }
    }
    path.pop_back();
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n;
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1, -1);
    dfs1(1, -1);
    return 0;
}


Measured memory_bytes: 13052
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    S = iss()
    mx = S.count('R') * S.count('G') * S.count('B')

    for i in range(N):
        for j in range(i+1, N):
            k = j + j - i
            if k < N and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                mx -= 1
    print(mx)


if __name__ == '__main__':
    main()


Measured memory_bytes: 37440
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD1 1000000007

int main() {
  int n;
  cin >> n;
  vi p(n);
  rep(i, n) cin >> p.at(i);
  int num = 0;

  for (int i = 1; i <= n - 2 ; i++) {
    if (p[i - 1] < p[i] && p[i] < p[i + 1]) num++;
    else if (p[i - 1] > p[i] && p[i] > p[i + 1]) num++;
  }

  cout << num << endl;


}


Measured memory_bytes: 256
package main

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

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var N int
	if scanner.Scan() {
		N, _ = strconv.Atoi(scanner.Text())
	}
	A := make([]int, N)
	var sum int
	for i := 0; i < N; i++ {
		if scanner.Scan() {
			A[i], _ = strconv.Atoi(scanner.Text())
			sum += A[i]
		}
	}
	x := sum / N

	var ans1 int
	for _, v := range A {
		ans1 += (v - x) * (v - x)
	}
	var ans2 int
	x++
	for _, v := range A {
		ans2 += (v - x) * (v - x)
	}
	var ans int
	if ans1 < ans2 {
		ans = ans1
	} else {
		ans = ans2
	}

	var wtr = bufio.NewWriter(os.Stdout)
	fmt.Fprintln(wtr, ans)
	_ = wtr.Flush()
}


Measured memory_bytes: 640
from collections import deque
H, W = map(int, input().split())
K = []
for i in range(H):
    A = list(input())
    K.append(A)
P = deque([[0, 0, 1]])
used = [[0]*W for _ in range(H)]
used[0][0] = 1
while(True):
    if len(P) == 0:
        break
    h, w, c = P.popleft()
    if h == H-1 and w == W-1:
        break
    for i, j in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
        if 0 <= h+i <= H-1:
            if 0 <= w+j <= W-1:
                if K[h+i][w+j] == ".":
                    if used[h+i][w+j] == 0:
                        used[h+i][w+j] = 1
                        P.append([h+i, w+j, c+1])

ans = 0
for i in range(H):
    for j in range(W):
        if K[i][j] == ".":
            ans += 1
if h == H-1 and w == W-1:
    print(ans - c)
else:
    print(-1)

Measured memory_bytes: 74300
#include<stdio.h>

int main(void){
    int r,c;
    int i,j,sum;

    scanf("%d %d",&r,&c);
    int A[r+1][c+1];
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&A[i][j]);
        }
    }

    for(i=0;i<r;i++){
        sum=0;
        for(j=0;j<c;j++){
            sum+=A[i][j];
        }
        A[i][c]=sum;
    }
    for(i=0;i<c+1;i++){
        sum=0;
        for(j=0;j<r;j++){
            sum+=A[j][i];
        }
        A[r][i]=sum;
    }

    for(i=0;i<r+1;i++){
        for(j=0;j<c+1;j++){
            if(j==0) printf("%d",A[i][j]);
            else printf(" %d",A[i][j]);
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)



typedef long long ll;
int H, W;
int A[405][405];
ll dp[405][405][405];
//-----------------------------------------------------------------
int main() {
	cin >> H >> W;
	rep(y, 0, H) rep(x, 0, W) cin >> A[y][x];

	dp[0][0][0] = A[0][0];

	int N = max(H, W);
	rep(i, 0, N * 2) rep(j, 0, N) rep(k, j, N) {
		int ax = j;
		int ay = i - j;
		int bx = k;
		int by = i - k;
		if (ay < 0) continue;
		if (by < 0) continue;

		//printf("dp[%d][%d][%d] = (%d, %d) and (%d, %d)\n", i, j, k, ax, ay, bx, by);

		if (ax < N - 1 && bx < N - 1)
			dp[i + 1][j + 1][k + 1] = max(dp[i + 1][j + 1][k + 1], dp[i][j][k] + ((ax + 1 == bx + 1 && ay == by) ? A[ay][ax + 1] : A[ay][ax + 1] + A[by][bx + 1]));

		if (ax < N - 1 && by < N - 1)
			dp[i + 1][j + 1][k] = max(dp[i + 1][j + 1][k], dp[i][j][k] + ((ax + 1 == bx && ay == by + 1) ? A[ay][ax + 1] : A[ay][ax + 1] + A[by + 1][bx]));

		if (ay < N - 1 && bx < N - 1)
			dp[i + 1][j][k + 1] = max(dp[i + 1][j][k + 1], dp[i][j][k] + ((ax == bx + 1 && ay + 1 == by) ? A[ay + 1][ax] : A[ay + 1][ax] + A[by][bx + 1]));

		if (ay < N - 1 && by < N - 1)
			dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k] + ((ax == bx && ay + 1 == by + 1) ? A[ay + 1][ax] : A[ay + 1][ax] + A[by + 1][bx]));

		if (ax == bx && ay == by) {
			if (ax == W - 1 && ay == H - 1) {
				cout << dp[i][j][k] << endl;
				return 0;
			}
		}

		//printf("dp[%d][%d][%d] = %lld\n", i, j, k, dp[i][j][k]);
	}
}

Measured memory_bytes: 190848
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int H,W,N;
    cin >> H >> W >> N;
    int sr,sc;
    cin >> sr >> sc;
    string S,T;
    cin >> S >> T;

    pii s1={1,H}, s2={1,W};
    RREP(i, N){
        switch (T[i])
        {
        case 'L': s2.se = min(s2.se+1, W);break;
        case 'R': s2.fi = max(s2.fi-1, 1);break;
        case 'U': s1.se = min(s1.se+1, H);break;
        case 'D': s1.fi = max(s1.fi-1, 1);break;
        }
        switch (S[i])
        {
        case 'L': s2.fi++;break;
        case 'R': s2.se--;break;
        case 'U': s1.fi++;break;
        case 'D': s1.se--;break;
        }
        if(s1.fi>s1.se||s2.fi>s2.se){
            pr("NO");
            return 0;
        }
    }
    YES(s1.fi<=sr&&sr<=s1.se&&s2.fi<=sc&&sc<=s2.se);
}

Measured memory_bytes: 3916
#include<stdio.h>
#include<cstdlib>
#include<fstream>
#include<iostream>
#include<complex>
#include<math.h>
#include<string>
#include<sstream>

using namespace std;

int main(){
    int A;
    cin >> A;
    int B;
    cin >>B;
    if(A<=2*B){
        cout<<0<<endl;
    }
    else{
        cout<<(A-2*B)<<endl;
    }
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

struct Cake{
    ll x,y,z;
};

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

    vector<Cake> cakes(N);
    REP(i,N) cin >> cakes[i].x >> cakes[i].y >> cakes[i].z;

    

    ll ans = 0;
    
    REP(x,2){
        REP(y,2){
            REP(z,2){
                vector<ll> sum(N,0);
                REP(i,N){
                    sum[i] += x? cakes[i].x: -cakes[i].x;
                    sum[i] += y? cakes[i].y: -cakes[i].y;
                    sum[i] += z? cakes[i].z: -cakes[i].z;
                }
                sort(ALL(sum), greater<ll>());
                ll s = 0;
                REP(j,M) s += sum[j];
                ans = max(ans, s);
            }
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main{

    static char[] expr;
    static int now;

    private static int expression(){
	int res=term();
	while(true){
	    char c=expr[now++];
	    if(c=='+')res+=term();
	    else if(c=='-')res-=term();
	    else break;
	}
	return res;
    }

    private static int term(){
	int res=fact();
	while(true){
	    char c=expr[now++];
	    if(c=='*')res*=fact();
	    else if(c=='/')res/=fact();
	    else break;
	}
	now--;
	return res;
    }
    
    static int fact(){
	char c=expr[now++];
	if(c=='(')return expression();
	if(c=='-')return -fact();
	if(c=='+')return fact();
	int x=c-'0';
	while(true){
	    c=expr[now++];
	    if(Character.isDigit(c)){
		x*=10;
		x+=c-'0';
	    }
	    else break;
	}
	now--;
	return x;
    }

    public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
	int t=sc.nextInt();
	while(t--!=0){
	    expr=sc.next().toCharArray();
	    now=0;
	    System.out.println(expression());
	}
    }
    
}

Measured memory_bytes: 17172
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
string a, b;
ll n, m;
ll x;

ll gcd(ll x, ll y) {
    if(x < y) swap(x, y);
    while(y > 0) {
        ll temp = x % y;
        x = y;
        y = temp;
        if(x < y) swap(x, y);
    }
    return x;
}

ll lcm(ll x, ll y) {
    return 1LL * x / gcd(x, y) * 1LL * y;
}

map<ll, char> aa, bb;


int main() {
    cin>>n>>m;
    cin>>a;
    cin>>b;

    ll x = lcm(n, m);

    ll curr = 1LL;
    ll xx = x / n;
    for(int i=0;i<n;i++) {
        aa[curr] = a[i];
        curr += xx;
    }
    curr = 1LL;
    ll yy = x / m;
    for(int i=0;i<m;i++) {
        bb[curr] = b[i];
        curr += yy;
    }

    bool check = true;
    for(auto i:aa) {
        if(bb[i.first] != i.second && (bb[i.first] >= 'a' && bb[i.first] <= 'z')) check = false;
    }

    if(check) cout<<x<<"\n";
    else cout<<"-1\n";

    return 0;
}


Measured memory_bytes: 15616
from decimal import *
import math
n = int(input())
a, b = map(int, input().split())
for i in range(n - 1):
    c, d = map(int, input().split())
    q = Decimal(max(math.ceil(a / c), math.ceil(b / d)))
    a, b = c * q, d * q

print(a + b)

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

using namespace std;

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,ll> pii;
const ll mod = 1e9+7;

vector<vector<pii>> r;

const ll INF = 1LL<<50;
vector<ll> dijkstra(int s){
	priority_queue< pii, vector<pii>, greater<pii> > que;
	vector<ll> d(sz(r), INF); 
	d[s] = 0;    //スタート地点は0
	que.push(pii(0, s));
	while(!que.empty()){
		int cost, v; tie(cost, v) = que.top();
		que.pop();
		if(d[v] < cost) continue;
		for(const auto& rp : r[v]){ 
			int rct, rto; tie(rto, rct) = rp;
			if(d[rto] > d[v] + rct){
				d[rto] = d[v] + rct;
				que.push(pii(d[rto], rto));
			}
		}
	}
	return d;
}


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n,q,k;
	cin >>n;
		r.resize(n);
	rep(i,n-1){
		int a,b, c;
		cin >>a >>b >>c;
		r[a-1].push_back(pii(b-1,c));
		r[b-1].push_back(pii(a-1,c));
	}
	cin >>q >>k;
	auto ds = dijkstra(k-1);
	//for(auto x :ds) printf("%lld, ",x); puts("");
	rep(i,q){
		int x,y; cin >>x >>y;
		cout << ds[x-1] + ds[y-1] <<"\n";
	}
	return 0;
}


Measured memory_bytes: 11120
def bubble_sort(a,n):
    for i in range(n):
        for j in range(n-1,i,-1):
            if a[j][1] < a[j-1][1]:
                a[j], a[j-1] = a[j-1], a[j]
    return a

def selection_sort(a,n):
    for i in range(n):
        minj = i
        for j in range(i+1,n):
            if a[j][1] < a[minj][1]:
                minj = j
        a[i],a[minj] = a[minj],a[i]
    return a

def is_stable(a, sa, n):
    stable = True
    for i in range(n-1):
        if sa[i][1] == sa[i+1][1] and a.index(sa[i]) > a.index(sa[i+1]):
                stable = False
                break
    if stable:
        print('Stable')
    else:
        print('Not stable')

n = int(input())
a = [ (s[0], int(s[1:])) for s in input().split() ]
ba = bubble_sort(a.copy(),n)
print(*[ s[0]+str(s[1]) for s in ba])
is_stable(a,ba,n)
ia = selection_sort(a.copy(),n)
print(*[ s[0]+str(s[1]) for s in ia])
is_stable(a,ia,n)


Measured memory_bytes: 5616
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;

int main()
{
  int A, B, C;

  cin >> A >> B >> C;

  if ((A - C) * (C - B) >= 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import sys
def f(s,d,g,c):
	if d>3:return c
	for n in range(10):
		if s+n==g:return c+1
		elif s+n>g:return c
		else:c=f(s+n,d+1,g,c)
	return c
for l in sys.stdin:
	print f(0,0,int(l),0)

Measured memory_bytes: 4196
#include <stdio.h>

int bubbleSort(int A[], int N)
{
  int flag = 1, j, tmp, count = 0, i = 0;

  while(flag){
    flag = 0;
    for(j = N - 1; j >= i + 1 ; j--){       //配列の末尾から順番に大きさを比較していく」
      if(A[j] < A[j-1]){
        tmp = A[j];
        A[j] = A[j-1];
        A[j-1] = tmp;
        flag = 1;
        count++;
      }
    }
  }
  return count;
}

int main(void)
{
  int n, i, a[100], count;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  count = bubbleSort(a, n);

  for(i = 0; i < n; i++){
    if(i) printf(" ");
    printf("%d", a[i]);
  }
  printf("\n");
  printf("%d\n", count);    //上のループで最後に空白が入るのでn-1までにしてループの外に最後の出力をする


  return 0;
}



Measured memory_bytes: 2092
#include <stdio.h>
#include <math.h>

double S(double a, double b, double c){
	double s = (a+b+c)/2;
	return sqrt(s*(s-a)*(s-b)*(s-c));
}
	
int main(void){
	double x1,y1,x2,y2,x3,y3,xp,yp,a,b,c,xa,xb,xc;
	while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
				  &x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF){
		a = sqrt(pow(x1-x2,2)+pow(y1-y2,2));
		b = sqrt(pow(x1-x3,2)+pow(y1-y3,2));
		c = sqrt(pow(x2-x3,2)+pow(y2-y3,2));
		xa = sqrt(pow(x3-xp,2)+pow(y3-yp,2));
		xb = sqrt(pow(x2-xp,2)+pow(y2-yp,2));
		xc = sqrt(pow(x1-xp,2)+pow(y1-yp,2));
		if (S(a,xb,xc)+S(b,xc,xa)+S(c,xa,xb)-S(a,b,c) > 0.0000001){
			puts ("NO");
		}else{
			puts ("YES");
		}
	}
	return 0;
}

Measured memory_bytes: 612
require 'prime'

mod = 10 ** 9 + 7

N = gets.to_i
h = Hash.new(0)

(2..N).each do |i|
  (i.prime_division.to_h).each do |k,v|
    h[k] += v
  end
end

ans = 1
h.each do |k, v|
  ans = ans * (v+1) % mod
end

puts ans

  

Measured memory_bytes: 2428
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int a,b;
  cin>>a>>b;
  if(a<=5) cout<<0<<endl;
  else if(a<=12) cout<<b/2<<endl;
  else cout<<b<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int c2(int x){
    if(x<=1)return 0;
    return x*(x-1)/2;
}

int main(){
    int N,M;
    cin>>N>>M;
    //NC2+MC2
    cout<<c2(N)+c2(M)<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>
#define mod 998244353
long long sum[10][3000000];
long long base[3000000];
long long tree[3000000];
long long left[3000000];
long long right[3000000];
long long lazy[3000000];
int l,r,value;
void build(int l,int r,int k){
	left[k]=l;right[k]=r;
	if (l==r){
		tree[k]=1;
		return;
	}
	int mid=(l+r)/2;
	build(l,mid,k*2);
	build(mid+1,r,k*2+1);
	tree[k]=((tree[k*2]*base[r-mid]% mod)+tree[k*2+1])% mod;
}
void laze(int k){
	if (lazy[k]==0) return;
    lazy[k*2]=lazy[k]; lazy[k*2+1]=lazy[k];
    tree[k]=sum[lazy[k]][right[k]-left[k]+1];
    lazy[k]=0; 
}

void update(int l,int r,int k,int value){
	laze(k);
	if (r<left[k]||l>right[k]) return;
	if (left[k]>=l&&right[k]<=r) {
		lazy[k]=value;
		laze(k);
		return;
	}   
	    int mid=(left[k]+right[k])/2;
		update(l,r,k*2,value);
		update(l,r,k*2+1,value);
		tree[k]=((tree[k*2]*base[right[k]-mid]% mod)+tree[k*2+1])% mod;
}
int main(){
	int n,q;scanf("%d %d",&n,&q);
	for (int i=1;i<=9;i++){
		sum[i][1]=i;
		for (int j=2;j<=n;j++){
			sum[i][j]=((sum[i][j-1]*10% mod)+i)% mod;
		}
	}
	base[0]=1;
	for (int i=1;i<=n;i++){
		base[i]=(base[i-1]*10)% mod;
	}
	build(1,n,1);
	for (int i=1;i<=q;i++){
		scanf("%d %d %d",&l,&r,&value);
		update(l,r,1,value);
		printf("%lld\n",tree[1]);
	}
}

Measured memory_bytes: 38592
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define st string
using namespace  std;
int main()
{
    ll a,c=0,d=0;
    st b;
    cin>>a>>b;
    for(ll i=0;i<b.size();i++)
    {
        if(b[i]=='I')
            c++;
        else
            c--;
        d=max(d,c);
    }
    cout<<d;
}


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

int main(){
    int n;
    cin >> n;
    map<int, int> m;
    rep(i, n){
        int t;
        cin >> t;
        m[i+1] = t;
    }
    int tmp = 1;
    rep(i, n){
        tmp = m[tmp];
        if(tmp==2){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
 
//****************************************************                
#define f(var,start,end) for(ll var = start; var <end ; ++var)
#define rf(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define vvll vector<vector<ll>>
#define mtp make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define nl cout<<"\n"
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions
void solve();

int binary(int a[],int l,int r,int find)
{
    if(l>r)
    {
        return -1; 
    }else
    {
        int mid=(l+r)/2;
        if(a[mid]==find)
        {
            return mid+1;
        }else if(a[mid]>find)
        {
            binary(a,l,mid-1,find);
        }else
        {
            binary(a,mid+1,r,find);
        }   
    }   
}

int main()
{
    FAST_IO;
    ll testcases = 1;
    // cin >> testcases; //comment for 1 test case
    while(testcases--)
    {
        solve();
    }
}

void solve()
{
	ll n;
	cin>>n;
	vll a(n);
	vll mp(100001,0);
	ll sum=0;
	f(x,0,n)
	{
		cin>>a[x];
		mp[a[x]]++;
		sum+=a[x];
	}

	ll q;
	cin>>q;
	while(q--)
	{
		ll b,c;
		cin>>b>>c;
		sum=sum-mp[b]*b;
		sum=sum+mp[b]*c;
		mp[c]+=mp[b];			
		mp[b]=0;
		cout<<sum;
		nl;
	}
}

Measured memory_bytes: 4748
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K, N = MAP()
A = LIST()
B = []
for i in range(N-1):
    B.append(A[i+1]-A[i])
B.append(K - A[N-1] + A[0])
# print(B)
c = []
for b in B:
    c.append(K-b)
print(min(c))

Measured memory_bytes: 27808
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int calcDigitSum(int n){
	int res = 0;
	while(n > 0){
		res += (n % 10);
		n /= 10;
	} // end while
	return res;
}

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

	int n; cin >> n;

	int sum = calcDigitSum(n);
	bool res = (n % sum == 0);

	cout << (res ? "Yes" : "No") << endl;
	
	return 0;
}

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

#define ll long long int

#define endl "\n"

int main(){

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int t=1;
    // cin>>t;

    while(t--){
        string s;
        cin>>s;
        if(s[s.size()-1]=='s'){
            cout<<s<<"es"<<endl;
        }
        else{
            cout<<s<<"s"<<endl;
        }
    }


    return 0;
}

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

int main() {
    int x, y;
    cin >> x >> y;
    vector<int> a = {1, 3, 5, 7, 8, 10, 12};
    vector<int> b = {4,6,9,11};
    vector<int> c = {2};
    vector<vector<int>> all = {a,b,c};
    for(auto v: all){
        if(find(v.begin(), v.end(), x) != v.end() && find(v.begin(),v.end(),y) != v.end()){
            cout << "Yes" << endl;
            exit(0);
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,m,a[1010],b[1010],c[1010] = {};
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		cin >> a[i] >> b[i];
		for(int j = 0;j < b[i];j++){
			int cc;
			cin >> cc; cc--;
			c[i] += (1 << cc);
		}
	}
	int dp[1010][1 << 12];
	for(int i = 0;i <= m;i++){
		for(int j = 0;j < (1 << n);j++) dp[i][j] = INF;
	}
	dp[0][0] = 0;
	for(int i = 0;i < m;i++){
		for(int j = 0;j < (1 << n);j++){
			chmin(dp[i + 1][j],dp[i][j]);
			chmin(dp[i + 1][j | c[i]],dp[i][j] + a[i]);
		}
	}
	if(dp[m][(1 << n) - 1] == INF) cout << -1 << endl;
	else cout << dp[m][(1 << n) - 1] << endl;
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 100 + 5, K = 1e5 + 5;

int dp[K][3];
int a[N];
int n, ans = 0;

int sol(int k, int turn) {
    int f = 1;

    int &ret = dp[k][turn];
    if(ret != -1) return ret;

    ret = !turn;
    for(int i = 0; i < n; i++) {
        if(k - a[i] >= 0) {
            int ch = sol(k - a[i], turn ^ 1);
            if(turn) ret = max(ret, ch);
            else ret = min(ret, ch);
            f = 0;
        }
        else break;
    }

    if(f) {
        if(turn == 0) return 1;
        return 0;
    }

    return ret;
}

int main(){
//    fIO

//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    memset(dp, -1, sizeof(dp));
    int k;
    cin >> n >> k;

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

    cout << (sol(k, 1) == 1 ? "First" : "Second") << "\n";
}








Measured memory_bytes: 10752
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  int n,m;
  cin >> n >> m;
  vector<vi> g(n, vi(n,INF));
  rep(i,n) g[i][i] = 0;

  vi a(m), b(m), c(m);
  rep(i,m){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    g[a[i]][b[i]] = g[b[i]][a[i]] = c[i];
  }

  rep(k,n)rep(i,n)rep(j,n) chmin(g[i][j], g[i][k] + g[k][j]);

  int ans = 0;
  rep(x,m){
    bool used = false;
    rep(i,n)rep(j,n){
      if(g[i][a[x]] + c[x] + g[b[x]][j] == g[i][j]) used = true;
    }
    if(not used) ans++;
  }
  cout << ans << endl;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> a(n,vector<int>(m));
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> a[i][j];
        }
    }
    int ans = n;
    while(!a[0].empty()){
        int cnt[m+1];
        fill(cnt,cnt+m+1,0);
        for(int i=0; i<n; i++){
            cnt[a[i][0]]++;
        }
        int b=0,c=0;
        for(int i=0; i<m+1; i++){
            if(c < cnt[i]){
                b = i;
                c = cnt[i];
            }
        }
        ans = min(ans,c);
        for(int i=0; i<n; i++){
            auto p = find(a[i].begin(),a[i].end(),b);
            a[i].erase(p);
        }
    }
    cout << ans << endl;
    return 0;
}


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

/*
Codeforces 766A
Codeforces 766B
ATCODER A
Codeforces 766C
HDU 3001
HDU 3007
*/


/*
Codeforces 766A 题意：
题意好坑，介绍了一堆子串的性质，长的一定不是短的的子串。
思路：
那么如果两个串相同-1
不相同取max(len1,len2)...
Codeforces 766B 题意：
给你n条线段，问能否取三个线段得一个三角形。
两边之和大于第三边。
枚举最大边，看能不能产生比他大的组合。
那其实sort完以后a<b<c只要看a+b是不是>c就好了
Codeforces 766C 题意：


AtCoder Beginner Contest 052 A题意：
输出大的面积？
思路：
max(A*B,C*D);
AtCoder Beginner Contest 052 B题意：
好像只要比较I和D的个数差，然后和0比大小就好了？
AtCoder Beginner Contest 052 C题意：
输出N!的因子个数mod1e9+7;
思路：
算质因子的个数，然后(质因子个数+1)的乘积mod1e+7就是answer.
原理就是一个质因子组合，+1就是意味着这个质因子可以没有，但是都没有就会出问题需要-1，然而1本身就是存在的。
所以得(质因子个数+1)的乘积mod1e+7就是answer？
那么只需要一个，质因子数分解？

HDU 3001 题意：
每个城市最多只玩一次，起点任意，求花费最少。
思路：



*/
const LL mod=1e9+7;
LL num[1010];
bool IsPrime[1010];
int Prime[1010],cnt;
void init()
{
    fill(IsPrime,IsPrime+1005,true);
    cnt=0;
    for(int i=2;i<=1000;i++)
    {
        if(!IsPrime[i]) continue;
        Prime[++cnt]=i;
        for(int j=i+i;j<=1000;j+=i)
            IsPrime[j]=false;
    }
}
void solve(int n)
{
    int q=sqrt(n);
    for(int i=1;i<=cnt&&Prime[i]<=n;i++)
    {
        while(n%Prime[i]==0)
        {
            num[Prime[i]]=num[Prime[i]]+1LL;
            n/=Prime[i];
        }
    }
}
int main()
{
    int n;
    memset(num,0,sizeof(num));
    init();
    scanf("%d",&n);
    for(int i=2;i<=n;i++)
        solve(i);
    LL ans=1LL;
    for(int i=2;i<=n;i++)
        if(num[i]) ans=ans*(num[i]+1LL)%mod;
    printf("%lld\n",ans);
    return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// Union-Find; 素集合データ構造
class UnionFind {
public:
    vector<long long> parent;
    long long n;
    UnionFind(long long x) :parent(x, -1), n(x){}
    bool unite(long long x, long long y){
        x = find(x); y = find(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        parent[x] += parent[y]; parent[y] = x;
        return true; }
    bool same(long long x, long long y){ return find(x) == find(y); }
    long long find(long long x){ return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    long long size(long long x){ return -parent[find(x)]; }
    long long leader(long long x){ return (parent[x] < 0 ? x : leader(parent[x])); }
};

int main(){
    Init();
    
    // n個の街
    ll n;
    cin >> n;
    UnionFind uf(n);
    
    // i個目の街の座標
    vi x(n), y(n);
    vector<pair<pair<ll, ll>, ll>> xy(n), yx(n);
    rep(i, n){
        cin >> x[i] >> y[i];
        xy[i] = make_pair(make_pair(x[i], y[i]), i);
        yx[i] = make_pair(make_pair(y[i], x[i]), i);
    }
    
    // x座標とy座標を分けて考える。ソートして距離が近いものを揃える
    sort(all(xy));
    sort(all(yx));

    // x座標とy座標ごとにコストを計算
    vector<pair<ll, pair<ll, ll>>> cost;
    for(ll i=0; i<n-1; i++){
        cost.emplace_back(make_pair(min(abs(xy[i].first.first - xy[i+1].first.first), abs(xy[i].first.second - xy[i+1].first.second)), make_pair(xy[i].second, xy[i+1].second)));
        cost.emplace_back(make_pair(min(abs(yx[i].first.first - yx[i+1].first.first), abs(yx[i].first.second - yx[i+1].first.second)), make_pair(yx[i].second, yx[i+1].second)));
    }
    sort(all(cost));

    // コストが小さい順に連結かどうか確認し、非連結であれば橋を作る
    ll ans = 0, i = 0;
    while(uf.size(0) < n){
        if(!uf.same(cost[i].second.first, cost[i].second.second)){
            uf.unite(cost[i].second.first, cost[i].second.second);
            ans += cost[i].first;
        }
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 16572
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		if (n <= k) {
			System.out.println(n * x);
		} else {
			System.out.println((k * x) + ((n - k) * y));
		}
	}

}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1025, INF = 0x3f3f3f3f, M = 2e6 + 5;
//
const ll LNF = 0x3f3f3f3f3f3f3f3f;
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, r, l) for (int i = r; i >= l; i--)
#define repe(i, u) for (int i = head[u]; i; i = nxt[i])
int n, a[N][N], vis[N];
bool flag;
bool ok() {
  for (int i = 1; i <= n; i++)
    if (a[i][0] != n) return 0;
  return 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - 1; ++j) cin >> a[i][j];
    a[i][0] = 1;
  }
  for (int z = 0; z <= 0x3f3f3f3f; z++) {
    if (ok()) {
      cout << z << '\n';
      return 0;
    }
    flag = 0;
    memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (vis[i] || a[i][0] == n) continue;
      int x = a[i][a[i][0]];
      if (!vis[i] && !vis[x] && a[x][a[x][0]] == i) {
        a[i][0]++;
        a[x][0]++;
        vis[i] = vis[x] = 1;
        flag = 1;
      }
    }
    if (!flag) {
      cout << -1 << '\n';
      return 0;
    }
  }
  return 0;
}


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

int main(){
	int A, B, C, j=0;
	cin >> A >> B >> C;
	for(int i=1; i<=B; i++){
		if(A*i%B==C){
		j++;
		break;
        }
	}
	if(j!=0) cout << "YES";
	else cout << "NO";
			
}
		

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


public class Main {
    Main(){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try{
            int i = Integer.parseInt(br.readLine());
            System.out.printf("%d:%d:%d\n", i/3600, (i%3600)/60, i%60);
        }catch(IOException e) {

        }
    }

    public static void main(String[] args){
        new Main();
    }
}



Measured memory_bytes: 24520
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll gcd(ll a, ll b) {		// ユークリッドの互除法
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll extgcd(ll a, ll b, ll& x, ll& y) {		// 拡張ユークリッドの互除法
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	} else {
		x = 1; y = 0;
	}
	return d;
}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,m;
	cin>>n>>m;
	string s,t;
	cin>>s>>t;
	ll g=gcd(n,m);
	ll a=n/g,b=m/g;
	REP(i,g) {
		if(s[i*a]!=t[i*b]) {
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<g*a*b<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int n;//使う個数
int s;//求める和
int ans;

long long int dp[10][1010];//dp[n][s]sをn個の整数で表すときの組み合わせ

int main()
{
  memset(dp,0,sizeof(dp));
  dp[0][0] = 1;
  for(int i = 0; i <101;i++){
    for(int j = 1000;j >-1;j--){
      for(int k = 9;k >0;k--){
	if(j-i>=0){
	  dp[k][j] +=dp[k-1][j-i];
	}
      }
    }
  }
  while(cin >>n>>s,n||s){
    cout <<dp[n][s]<<endl;
  } 
 
  return 0;
}

Measured memory_bytes: 1248
from collections import defaultdict

N, M = map(int, input().split())
a = list(map(int, input().split()))

tlst = [0] * (N + 1)
tlst[0] = 0
for i in range(1, N + 1):
    tlst[i] = (tlst[i - 1] + a[i - 1]) % M
d = defaultdict(int)
ans = 0
for i in range(N + 1):
    ans += d[tlst[i]]
    d[tlst[i]] += 1

print(ans)

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

int main(){
    int n;
    cin >> n;
    vector<int> dp(n+2, 1e9), h(n);
    for(int i=0; i<n; i++) cin >> h[i];

    dp[0] = 0;
    for(int i=0; i<n; i++){
        dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2] - h[i]));
        dp[i+1] = min(dp[i+1], dp[i]+abs(h[i] - h[i+1]));
    }

    cout << dp[n-1] << endl;
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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


int main() {

  ll x, k, d;
  cin >> x >> k >> d;
  x = abs(x);

  if(k <= x / d){
    cout << x - k*d << endl;
    return 0;
  }
  ll num = (x / d % 2);
  ll ans1, ans2; 
  ans1 = x % d;
  ans2 = ans1 - d;
  if(num==(k%2)){
    cout << abs(ans1) << endl;
  }else{
    cout << abs(ans2) << endl;
  }
  // cout << min(abs(ans1), abs(ans2)) << endl;
  return 0;


 
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

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

using namespace std;
using ll = long long;

priority_queue<ll, vector<ll>, greater<ll>> que;

void dfs(string s) {
    que.push(stol(s));
    if((int)s.size() == 10)return;
    
    if(s.back() == '0' || s.back() == '9'){
        string t0 = s, t1 = s;
        t0.push_back(s.back());
        t1.push_back(s.back() == '0' ? '1' : '8');
        dfs(t0), dfs(t1);
    }else{
        string t0 = s, t1 = s, t2 = s;
        t0.push_back(s.back() - 1);
        t1.push_back(s.back());
        t2.push_back(s.back() + 1);
        dfs(t0), dfs(t1), dfs(t2);
    }
}

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

    for(int i = 1; i < 10; i++){
        string t;
        t.push_back('0' + i);
        dfs(t);
    }
    for(int i = 0; i < k - 1; i++){
        cerr << que.top() << endl;
        que.pop();
    }
    cout << que.top() << endl;
}

Measured memory_bytes: 2424
#include<stdio.h>
int main()
{
	int a,b,c,flag=0;
	scanf("%d %d %d",&a,&b,&c);
	if(a+b+c==17 && a*b*c==175) flag=1;
	if(flag==1) 
		printf("YES\n");
	else 
		printf("NO\n");
	return 0;
}

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

int main() {
  int n, ans = -1;
  cin >> n;
  int a[n + 1], cond = 1;
  rep(i, n) cin >> a[i + 1];
  rep(i, 200000) {
    cond = a[cond];
    if (cond == 2) {
      ans = i + 1;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int h, w, k; cin >> h >> w >> k;

	vector<vector<int>> amida(h+1, vector<int>(w));

	vector<vector<int>> dp(h+1, vector<int>(w));
	dp[0][0] = 1;

	for (int i = 1; i < h+1; i++) {
		for (int bar = 0; bar < (1 << w - 1); bar++) {

			bool ng = false;
			//2個続いている場所がないかのチェック
			
			for (int j = 0; j < w - 2; j++) {
				if ((bar >> j) % 4 == 3) {
					ng = true;
					break;
				}
			}

			if (ng)continue;

			//置換の対応列を作る
			vector<int> swaprow(w);
			for (int j = 0; j < w; j++) {
				swaprow[j] = j;
			}

			for (int j = 0; j < w-1; j++) {
				if ((bar >> j) % 2 == 1) {
					swap(swaprow[j], swaprow[j + 1]);
				}
			}

			//遷移

			for (int j = 0; j < w; j++) {
				dp[i][swaprow[j]] += dp[i - 1][j];
				dp[i][swaprow[j]] %= MOD;
			}

		}
	}

	cout << dp[h][k - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds; 
using namespace std;



typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
 
//defines
typedef long long ll;
typedef long double ld;
ll n,m,k,tar,a,b,d,e;
map<ll,ll>ff;


void solve()
{
   cin>>n>>m>>a>>b>>k;
   ll ans=abs(((60*n)+m)-((60*a)+b));
   if(k<=ans)
   cout<<ans-k;
   else cout<<0;
   return ;
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   
        solve();
    
        
    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<vector>
#include<iostream>
#include<set>
using namespace std;




int main() {
	int a,b,c;
	cin >> a >> b >> c;
	
	set<int> se;
	se.insert(a);
	se.insert(b);
	se.insert(c);
	
	if(se.size() == 2){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
    return 0;
}


Measured memory_bytes: 256