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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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 (a>b) { a=b; return 1; } return 0; }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}


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

    ll N;
    cin >> N;

    auto mp = prime_factor(N);
    ll res = 0;
    for(auto x: mp){
        ll tot = 0;
        ll now = 1;
        while(1){
            if(tot + now > x.second) break;
            tot += now;
            now++;
            res++;
        }
    }
    cout << res << endl;

    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i=1;i<s.size();++i){
        if(s[i] != s[i-1])ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
from heapq import heappush, heappop
def dijkstra(graph:list, node:int, start:int) -> list:
    # graph[node] = [(cost, to)]
    inf = float('inf')
    dist = [inf]*node

    dist[start] = 0
    heap = [(0,start)]
    while heap:
        cost,thisNode = heappop(heap)
        for NextCost,NextNode in graph[thisNode]:
            dist_cand = dist[thisNode]+NextCost
            if dist_cand < dist[NextNode]:
                dist[NextNode] = dist_cand
                heappush(heap,(dist[NextNode],NextNode))
    return dist

N = int(input())
g = [[] for _ in range(N)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    g[a-1].append((c,b-1))
    g[b-1].append((c,a-1))

Q,K = map(int,input().split())
dist = dijkstra(g,N,K-1)
for _ in range(Q):
    x,y = map(int,input().split())
    print(dist[x-1]+dist[y-1])

Measured memory_bytes: 92960
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s= sc.nextInt();
        long div=1_000_000_007;
        long[]ans=new long[s+1];
        
        for (int i = 1; i <= s; i++) {
            if(i<=2)      ans[i]=0;
            else if(i==3) ans[i]=1;
            else          ans[i]=(ans[i-1]+ans[i-3])%div;
        }
        System.out.println(ans[s]);
    }
}

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

int main(){
    int H,W;
    
    while(1){
        cin >> H >> W;
        if (H == 0 && W == 0) break;    
        for ( int i = 0; i < H; i++ ){
            for ( int j = 0; j < W; j++ ){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    string S;
    cin >> S;

    if (S == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (S == "Cloudy") {
        cout << "Rainy" << endl;
    } else if (S == "Rainy") {
        cout << "Sunny" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

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




int main(){
    int N; std::cin >> N;
    std::vector<std::vector<int>> G(N);
    std::vector<int> d0(N, -1), dN(N, -1);
    {
        int a, b;
        for(int i(0), i_len(N-1); i < i_len; ++i){
            std::cin >> a >> b;
            --a; --b;
            G[a].push_back(b);
            G[b].push_back(a);
        }
    }
    d0[0] = 0;
    std::queue<int> que;
    que.push(0);
    while(!que.empty()){
        int v(que.front()); que.pop();
        for(int e: G[v]){
            if(d0[e] != -1) continue;
            d0[e] = d0[v] + 1;
            que.push(e);
        }
    }
    dN[N-1] = 0;
    que.push(N-1);
    while(!que.empty()){
        int v(que.front()); que.pop();
        for(int e: G[v]){
            if(dN[e] != -1) continue;
            dN[e] = dN[v] + 1;
            que.push(e);
        }
    }
    int cnt(0);
    for(int i(0); i < N; ++i){
        if(d0[i] <= dN[i]) ++cnt; 
    }
    std::cout << ((2*cnt > N) ? "Fennec": "Snuke") << std::endl;
    return 0;
}


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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int H,W,K;
  cin>>H>>W>>K;
  ll dp[110][10] = {0};
  dp[0][1] = 1;
  for(int h(0);h<H;h++){
    for(int w(1);w<=W;w++){
      // dp[h][w] から行くところを考える
      int x(0),y(0),z(0);
      for(int bit(0);bit<(1<<(W-1));bit++){
        bool flag = false;
        bool renzoku = false;
        vector<int> l;
        for(int i(0);i<W-1;i++){
          if(bit>>i&1){
            if(flag) renzoku = true;
            flag = true;
            l.push_back(i+1);
          }else{
            flag = false;
          }
        }
        if(renzoku) continue;
        bool flagx(false),flagz(false);
        for(int i(0);i<int(l.size());i++){
          if(l[i] == w) flagz = true;
          if(l[i] == w-1) flagx = true;
        }
        if(flagx) x++;
        else if(flagz) z++;
        else y++;
      }
      //cout << x << " " << y << " " << z << endl;
      if(w != 0) (dp[h+1][w-1] += (dp[h][w]*x)%MOD)%=MOD;
      (dp[h+1][w] += (dp[h][w]*y)%MOD)%=MOD;
      if(w != W) (dp[h+1][w+1] += (dp[h][w]*z)%MOD)%=MOD;
    }
  }
  //cout << endl;
  //for(int i(0);i<=H;i++){
    //for(int j(1);j<=W;j++){
      //cout << dp[i][j] << " ";
    //} 
    //cout << endl;
  //}
  cout << dp[H][K] << endl;
  return 0;
}



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

#define LL long long

#define FOR(INDEX, START, END) for (int INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (int INDEX = 0; INDEX < (COUNT); ++INDEX)

int main()
{
    int A, B;
    cin >> A >> B;
    
    cout << (A * B) - A - B + 1 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int N,M;
int P[100000],Y[100000];
vector<int>yd[100001];

int main(){
    scanf("%d%d",&N,&M);
    rep(i,M)scanf("%d%d",&P[i],&Y[i]),yd[P[i]].push_back(Y[i]);
    rep(i,N)sort(yd[i+1].begin(),yd[i+1].end());
    rep(i,M)printf("%012lld\n",ll(P[i])*1000000+int(lower_bound(yd[P[i]].begin(),yd[P[i]].end(),Y[i])-yd[P[i]].begin())+1);
}

Measured memory_bytes: 7680
#include<iostream>
#include<string>
using namespace std;
int main(){
	string S;
	long K,sum=0;
	long len,equal,count=0,countL;
	long firstC,middleC,lastC;
	bool first=false;
	cin>>S>>K;
	len = S.length();
	equal=1;
	for(int i=1;i<len;i++){
		if(S[i]==S[i-1]){
			equal++;
		}else{
			if(first==false){
				count=equal;
				first=true;
				equal=1;
			}
			if(equal>=2&&equal%2==0){
				sum+=equal/2;
				equal = 1;
			}else if(equal>=2&&equal%2==1){
				sum+=(equal-1)/2;
				equal = 1;
			}else equal = 1;
		}
	}
	if(first==false){
		sum=((len*K)-(len*K)%2)/2;
		cout<<sum;
		return 0;
	}
	countL=equal;
	firstC = sum+(count-count%2)/2;
	if(S[0]==S[len-1]){
		middleC = sum+((count+countL)-(count+countL)%2)/2;
	}else{
		middleC = sum+(count-count%2)/2+(countL-countL%2)/2;
	}
	lastC = middleC+(countL-countL%2)/2;

	if(K==1){
		if(countL>=2&&countL%2==0)sum+=countL/2;
		else if(countL>=2&&countL%2==1)sum+=(countL-1)/2;
		if(count>=2&&count%2==0)sum+=count/2;
		else if(count>=2&&count%2==1)sum+=(count-1)/2;
	}else sum = firstC+middleC*(K-2)+lastC;
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
d,x = map(int,input().split())
a = []
while True:
  try:
    a.append(int(input()))
  except:
    break

lis = []
for i in range(n):
  tmp = d//a[i]
  if d%a[i]!=0:
    tmp +=1
  lis.append(tmp)

ans = sum(lis) + x
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

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

	vec H(N);

	REP(i, N) {
		cin >> H[i];
	}

	FOR(i,1,N){
		if(H[i]<H[i-1]) H[i]++;
		if(H[i]<H[i-1]) {
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    map<char,int> mp;
    rep(i, n) rep(j, m) {
        char c;
        cin >> c;
        mp[c]++;
    }
    int odd = 0, two = 0;
    for(auto p : mp) {
        if(p.second & 1) odd++;
        if(p.second % 4 == 2) two++;
    }
    int h = (n & 1) && (m & 1);
    int w = (n / 2) * (m & 1) + (m / 2) * (n & 1);
    if(h == odd && two <= w) Yes();
    else No(); 
}


Measured memory_bytes: 3640
def main():
    import sys
    input = sys.stdin.buffer.readline

    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.root = [-1] * (n + 1)
            self.rnk = [0] * (n + 1)

        def find_root(self, x):
            if self.root[x] < 0:
                return x
            else:
                self.root[x] = self.find_root(self.root[x])
                return self.root[x]

        def unite(self, x, y):
            x = self.find_root(x)
            y = self.find_root(y)
            if x == y:
                return
            elif self.rnk[x] > self.rnk[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rnk[x] == self.rnk[y]:
                    self.rnk[y] += 1

        def isSameGroup(self, x, y):
            return self.find_root(x) == self.find_root(y)

        def size(self, x):
            return -self.root[self.find_root(x)]

    N, M = map(int, input().split())
    X = [0] + list(map(int, input().split()))
    edge = [None] * M
    for i in range(M):
        edge[i] = tuple(map(int, input().split()))
    edge.sort(key=lambda e: e[2])

    UF = UnionFind(N+1)
    edge_num = [0] * (N+1)
    ok_num = [0] * (N+1)
    for a, b, y in edge:
        if UF.isSameGroup(a, b):
            root_a = UF.find_root(a)
            edge_num[root_a] += 1
            if X[root_a] >= y:
                ok_num[root_a] += 1
        else:
            root_a = UF.find_root(a)
            root_b = UF.find_root(b)
            UF.unite(a, b)
            root_new = UF.find_root(a)
            root_old = root_a + root_b - root_new
            X[root_new] += X[root_old]
            X[root_old] = 0
            edge_num[root_new] += edge_num[root_old] + 1
            edge_num[root_old] = 0
            ok_num[root_new] += ok_num[root_old]
            ok_num[root_old] = 0
            if X[root_new] >= y:
                ok_num[root_new] = edge_num[root_new]
                ok_num[root_old] = 0
    print(M - sum(ok_num))


if __name__ == '__main__':
    main()


Measured memory_bytes: 105272
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	W := make([]string, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&W[i])
	}

	M := make(map[string]struct{})
	M[W[0]] = struct{}{}

	for i := 1; i < N; i++ {
		_, exist := M[W[i]]
		if exist {
			fmt.Println("No")
			return
		}
		if W[i-1][len(W[i-1])-1] != W[i][0] {
			fmt.Println("No")
			return
		}
		M[W[i]] = struct{}{}
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define lli long long int
#define timesave ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;


void solve(int t_case)
{
    string s1, s2;
    cin >> s1 >> s2;

    int l = s1.size();

    int cnt = 0;

    for(int i = 0; i < l; i++){
        if(s1[i] != s2[i]) cnt++;
    }

    cout << cnt << "\n";
}
 
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //timesave;

    int tc = 1, t_case = 1;
    //cin >> tc;
    while(tc--) solve(t_case++);
 
    return 0;
}

Measured memory_bytes: 3916
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
            System.out.println("Possible");
        } else {
            System.out.println("Impossible");
        }
    }
}

Measured memory_bytes: 23764
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0 ; i < n ; i ++){
			double x1 = sc.nextDouble();
			double y1 = sc.nextDouble();
			double x2 = sc.nextDouble();
			double y2 = sc.nextDouble();
			double x3 = sc.nextDouble();
			double y3 = sc.nextDouble();
			double p = ((y1-y3)*(y1*y1 -y2*y2 +x1*x1 -x2*x2) -(y1-y2)*(y1*y1 -y3*y3 +x1*x1 -x3*x3)) / (2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3));
			double q = ((x1-x3)*(x1*x1 -x2*x2 +y1*y1 -y2*y2) -(x1-x2)*(x1*x1 -x3*x3 +y1*y1 -y3*y3)) / (2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3));		
			double r = Math.sqrt((x1-p)*(x1-p)+(y1-q)*(y1-q));
			System.out.println(String.format("%.3f %.3f %.3f",p,q,r));
		}
	}
}

Measured memory_bytes: 20700
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int N, A, B, D, judgex[100000],judgey[100000],M, i, j;
long long Ans = 0;
string S;
int n = 0;

int main() {
	int x[55], y[55];
	cin >> N;
	for (i = 0; i < N; i++)
		cin >> x[i] >> y[i];
	for (i = 0; i < N; i++) {
		for (j = 0; j < N; j++) {
			if (i != j) {
				judgex[n] = x[i] - x[j];
				judgey[n] = y[i] - y[j];
				n += 1;
			}
		}
	}
	long long judge = 1;
	for (i = 0; i < n; i++) {
		for (j = i+1; j <= n; j++) {
				if ((judgex[i] == judgex[j]) && (judgey[i] == judgey[j]))
					judge += 1;
		}
		if (Ans < judge)
			Ans = judge;
		judge = 1;
	}
	Ans = N - Ans;
	cout << Ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
    int N;
    char s[110];
    cin>>N;
    scanf("%s",s);
    int ans=0;
    map<char,int>m;
    for(int i=1;i<N;i++){
            int counted=0;
        for(int j=0;j<=i;j++){
                m[s[j]]++;
        }
        for(int j=i+1;j<N;j++){
            if(m[s[j]]){
                counted++;
                m[s[j]]=0;
            }
        }
        ans=max(ans,counted);
        m.clear();
    }
    cout<<ans<<endl;
    return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
const int MOD = 1e9 + 7;

ll fact(int N)
{
    ll res = 1;
    rep(i, N) {
        res = res * (i + 1) % MOD;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);

    ll N, M;
    cin >> N >> M;

    if (N == M) {
        cout << ((fact(N) * fact(N) % MOD) * 2) % MOD << endl;
    } else if (abs(N - M) == 1) {
        cout << fact(N) * fact(M) % MOD << endl;
    } else {
        cout << 0 << endl;
    }
}

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

int N, M;

int main() {
    cin >> N >> M;
    vector<long long> a[3];
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            long long num; cin >> num;
            a[j].push_back(num);
        }
    }
    long long res = 0;
    for (int bit = 0; bit < (1<<3); ++bit) {
        vector<long long> b;
        for (int i = 0; i < N; ++i) {
            long long tmp = 0;
            for (int j = 0; j < 3; ++j) {
                if (bit & (1<<j)) tmp += a[j][i];
                else tmp -= a[j][i];
            }
            b.push_back(tmp);
        }
        sort(b.begin(), b.end(), greater<long long>());
        long long sum = 0;
        for (int i = 0; i < M; ++i) {
            sum += b[i];
        }
        res = max(res, sum);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define rer(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> ppi;
typedef vector<ll> vi;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest) { 
	cout << arg << " "; Debug(rest...); }
template<class T>ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<< ", ";out<<v.back();}out << "]";return out;}
template<class S, class T>ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";return out;}
const int MAX_N = 200010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
bool O[MAX_N];
vector<int> G[MAX_N];
bool used[MAX_N];

bool dfs(int v, int d) {
	used[v] = true;
	O[v] = d % 2;
	rep(i, 0, sz(G[v])) {
		int n = G[v][i];
		if(used[n]) {
			int td = O[n];
			if(td == O[v]) return true;
		}
		else {
			if(dfs(n, d + 1)) return true;
		}
	}
	return false;
}

void solve() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b;
		cin >> a >> b; a--; b--;
		G[a].pb(b); G[b].pb(a);
	}
	if(dfs(0, 0)) {
		cout << N * 1LL * (N - 1) / 2 - M << "\n"; 
		return;
	}
	int odd = 0, even = 0;
	rep(i, 0, N) {
		if(O[i]) odd++;
		else even++;
	}
	cout << odd * 1LL * even - M << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(5);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}






Measured memory_bytes: 8832
import sys

def test(N):
    MOD = 10**9+7
    U = (pow(10, N, MOD) - 1)%MOD
    notA = (pow(9, N, MOD) - 1)% MOD
    notB = (pow(9, N, MOD) - 1)% MOD
    A = (U - notA) % MOD
    B = (U - notB) % MOD
    AnorB = (pow(8, N, MOD) - 1)%MOD
    AorB = (U - AnorB) % MOD
    AandB = (A+B-AorB) %MOD
    #print(f"{U=}, {AorB=}, {A=}, {B=}, {AnorB=}")
    return AandB


def solve(N):
    MOD = 10**9+7
    dp = [[0, 0, 0, 0] for i in range(N+1)]
    dp[0] = [1, 0, 0, 0]
    A = 0
    B = 1
    C = 2
    D = 3
    for i in range(1, N+1):
        dp[i][A] = (dp[i-1][A]*8) % MOD
        dp[i][B] = (dp[i-1][A]   + dp[i-1][B]*9) % MOD
        dp[i][C] = (dp[i-1][A]   + dp[i-1][C]*9) % MOD
        dp[i][D] = (dp[i-1][B]   + dp[i-1][C]    + dp[i-1][D]*10) % MOD
        #print(i, dp[i], sum(dp[i]))
    return dp[N][D]

N = int(input())
print(test(N))
#print(solve(N))


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

int main() {
    int n;
    cin >> n;
    string s[n];
    for (int i = 0; i < n; i++)
        cin >> s[i];
    
    for (int i = 1; i < n; i++) {
        if (s[i-1][s[i-1].size()-1] != s[i][0]) {
            cout << "No" << endl;
            return 0;
        }
        for (int j = 0; j < i; j++) {
            if (s[i] == s[j]) {
                cout << "No" << endl;
                return 0;
            }
        } 
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(){
	int a,b,c;
	scanf(" %d%d%d",&a,&b,&c);
	//a < b && b < c;
	if(a < b && b < c){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 580
// ---------- begin chmin, chmax ----------
trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------

use proconio::*;
use proconio::marker::*;
use std::collections::*;
use std::cmp::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        p: [(i64, i64, Bytes); n],
    }
    let mut row = BTreeMap::new();
    let mut col = BTreeMap::new();
    let mut a = BTreeMap::new();
    let mut b = BTreeMap::new();
    for (x, y, s) in p.into_iter() {
        let c = s[0];
        if c == b'U' || c == b'D' {
            col.entry(x).or_insert(vec![]).push((y * 5, c));
        } else {
            row.entry(y).or_insert(vec![]).push((x * 5, c));
        }
        a.entry(x + y).or_insert(vec![]).push((10 * x, c));
        b.entry(x - y).or_insert(vec![]).push((10 * x, c));
    }
    let inf = 400000000;
    let mut ans = inf;
    for (_, row) in row {
        let mut row = row;
        row.sort();
        let mut p = -10 * inf;
        for (y, c) in row {
            if c == b'R' {
                p = y;
            } else {
                ans.chmin(y - p);
            }
        }
    }
    for (_, col) in col {
        let mut row = col;
        row.sort();
        let mut p = -10 * inf;
        for (y, c) in row {
            if c == b'U' {
                p = y;
            } else {
                ans.chmin(y - p);
            }
        }
    }
    for (_, a) in a {
        let mut a = a;
        a.sort();
        let mut p = -10 * inf;
        let mut q = -10 * inf;
        for (x, c) in a {
            match c {
                b'U' => {
                    ans.chmin(x - p);
                },
                b'D' => {
                    q = x;
                },
                b'L' => {
                    ans.chmin(x - q);
                },
                b'R' => {
                    p = x;
                },
                _ => unreachable!(),
            }
        }
    }
    for (_, a) in b {
        let mut a = a;
        a.sort();
        let mut p = -10 * inf;
        let mut q = -10 * inf;
        for (x, c) in a {
            match c {
                b'D' => {
                    ans.chmin(x - p);
                },
                b'U' => {
                    q = x;
                },
                b'L' => {
                    ans.chmin(x - q);
                },
                b'R' => {
                    p = x;
                },
                _ => unreachable!(),
            }
        }
    }
    if ans == inf {
        println!("SAFE");
    } else {
        println!("{}", ans);
    }
}

fn main() {
    run();
}


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

int main() {
  string w;
  int al[26]={};
  cin >> w;
  for(int i=0;i<w.size();i++) {
    al[w[i]-'a']++;
  }
  bool flag=true;
  for(int i=0;i<26;i++) {
    if(al[i]%2!=0) {
      flag=false;
      break;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main()
{
    string s, t; cin>>s>>t;
    set<string> res;
    int n=s.size(), m=t.size();
    for(int i=0; i+m<=n; ++i) {
        string x;
        for(int j=0; j<i; ++j) x+=s[j]=='?' ? 'a' : s[j];
        bool ok=true;
        for(int j=i; ok && j<i+m; ++j) {
            if (ok=(s[j]=='?' || s[j]==t[j-i]))
                x+=t[j-i];
        }
        for(int j=i+m; j<n; ++j) x+=s[j]=='?' ? 'a' : s[j];
        if (ok) res.insert(x);
    }
    cout<<(res.size() ? *begin(res) : "UNRESTORABLE")<<endl;
}

Measured memory_bytes: 256
sx,sy,tx,ty=map(int,input().split())
x=tx-sx
y=ty-sy

print("U"*y+"R"*x+"D"*y+"L"*(x+1)+"U"*(y+1)+"R"*(x+1)+"DR"+"D"*(y+1)+"L"*(x+1)+"U")




Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
string S;
int N;
ll dp[100005][4]; // idx番目でA,AB,ABCの数
ll H[100005];
// kまでのCの個数, Cをk番目と決めた時の,k-1番目までのBの個数, Bをj番目と決めた時の, j-1番目までのAの個数,

ll dfs(int idx, int status) {
  if (idx==-1) return status?0ll:1ll;
  if (status==0) return H[idx];
  if (dp[idx][status]>=0) return dp[idx][status];
  char c = S[idx];
  ll res = 0ll;
  if (c=='C' || c=='?') {
    res += dfs(idx-1, status); // このCは選ばない
    if (status==3) res += dfs(idx-1, 2);
  }
  if (c=='B' || c=='?') {
    res += dfs(idx-1, status);
    if (status==2) res += dfs(idx-1, 1);
  }
  if (c=='A' || c=='?') {
    res += dfs(idx-1, status);
    if (status==1) res += dfs(idx-1, 0);
  }
  res%=MOD;
  dp[idx][status] = res;
  return res;
}

int main() {
  INCANT;
  cin >> S;
  N = S.size();
  ll tmp = 1ll;
  rep(i, N) {
    if (S[i]=='?') {
      tmp*=3ll;
      tmp%=MOD;
      H[i] = tmp;
    } else H[i] = tmp;
  }
  rep(i, N) rep(j, 4) dp[i][j] = -1;
  ll res = dfs(N-1, 3);
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 12240
#include<iostream>
#include<math.h>

using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N], i, j, sum=0, avg, min;
    double b[3], cost[3];

    for (i=0; i<N; i++){
        cin >> a[i];
        sum += a[i];
    }
    for (j=0; j<3; j++){
        cost[j] = 0;
    }

    avg = sum / N;
    for (i=0; i<N; i++){
        b[0] = (double)(a[i] - avg);
        b[1] = (double)(a[i] - (avg + 1));
        b[2] = (double)(a[i] - (avg - 1));
        for (j=0; j<3; j++){
            cost[j] +=pow(b[j], 2);
        }
    }

    min = cost[0];
    for (i=1; i<3; i++){
        if (cost[i] < min){
            min = cost[i];
        }
    }
    cout << min;
    return 0;
}

Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b,c;
    cin>>n>>a>>b>>c;
    int l[n];
    int N=1;
    for(int i=0;i<n;i++){
        cin>>l[i];
        N*=4;
    }
    int m=1000000000;
    for(int i=0;i<N;i++){
        int A=0,B=0,C=0;
        int cost=-30;
        int I=i;
        for(int j=0;j<n;j++){
            if(I%4)cost+=10;
            if(I%4==1)A+=l[j];
            if(I%4==2)B+=l[j];
            if(I%4==3)C+=l[j];
            I/=4;
        }
        if(A==0 || B==0 || C==0)continue;
        m=min(m,cost+abs(A-a)+abs(B-b)+abs(C-c));
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  vector<int> b(n);
  int idx = 0;
  if (n % 2 == 0) {
    int r = n / 2, l = r - 1;
    for (int r = n / 2, l = r - 1; 0 <= l && r < n; --l, ++r) {
      b[r] = a[idx++];
      b[l] = a[idx++];
    }
  } else {
    b[n / 2] = a[idx++];
    for (int l = n / 2 - 1, r = n / 2 + 1; 0 <= l && r < n; --l, ++r) {
      b[r] = a[idx++];
      b[l] = a[idx++];
    }
  }
  REP(i, n) cout << b[i] << (i + 1 == n ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 3712
# n, k = 0
n, k = map(int, input().split())
# 0,1,2,3,,,,,,n
# k個選んだ時の最小値と最大値の差をk,k+1,k+2,,,,nと積算する

iResult = 0  # 答え
for i in range(k, n + 2):
#	print(i)
	#	min = 0
	#	max = 0
	#	for j in range(0, i):
	#		print('    ' + str(j))
	#		min = min + j
	#		max = max + n - j
#	print(iResult)
	iResult = iResult + i * (n - i + 1) + 1

print(iResult % (10**9 + 7))


Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> cost={0,2,5,5,4,5,6,3,7,6};
    vector<char> A(M);
    rep(i,M){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    vector<string> dp(N+1,"");
    rep(i,N+1){
        rep(j,M){
            if (dp[i]!=""||i==0){
                int k=i+cost[A[j]-'0'];
                if (k<=N&&dp[k]==""){
                    dp[k]=dp[i]+A[j];
                }
                else if (k<=N&&dp[k]!=""){
                    if ((dp[i]+A[j]).size()>dp[k].size()){
                        dp[k]=dp[i]+A[j];
                    }
                    else if ((dp[i]+A[j]).size()==dp[k].size())
                    dp[k]=max(dp[k],dp[i]+A[j]);
                }
            }
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 45056
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;cin>>n;
  vi A(n),A2;
  ll ma=0;
  ll cnt=0;
  for(auto &a:A){cin>>a;
    A2.pb(a);
    if(ma==a){
      cnt++;
    }else if(ma<a){
      ma=a;
      cnt=1;
    }
  }
  sort(ALL(A),greater<ll>());
  for(int i=0;i<n;i++)
    if(ma==A2[i])cout<<A[1]<<endl;
    else cout<<A[0]<<endl;
  return 0;
}


Measured memory_bytes: 4848
#
N=int(input())
S={}
for i in range(N):
    x=input()
    if x in S:
        S[x]+=1
    else:
        S[x]=1
t=max(S.values())
ans=[k for (k,v) in S.items() if v==t]
ans.sort()

for i in ans:
    print(i)
""""
#
while len(S):
    if len(S)==1:
        x = [S.pop(), 1]
        ans.append(x)
        break
    x = [S.pop(), 1]
    for i in S[:]:
        if x[0] == i:
            S.remove(i)
            x[1]+=1
    ans.append(x)
ans.sort()
ans.sort(key=lambda x:x[1],reverse=True)

for i in range(len(ans)):
    t=ans[0][1]
    if ans[i][1]==t:
        print(ans[i][0])



import queue

q=queue.Queue()
for i in S:
    q.put(i)

while not q.empty():
    x = [q.get(), 1]
    if len(ans)==0:
        ans.append(x)
        continue
    t=0
    for i in range(len(ans)):
        if x[0] == ans[i][0]:
            ans[i][1]+=1
            t+=1
            break
    if t==0:
        ans.append(x)
ans.sort()
ans.sort(key=lambda x:x[1],reverse=True)

for i in range(len(ans)):
    t=ans[0][1]
    if ans[i][1]==t:
        print(ans[i][0])

"""

Measured memory_bytes: 32096
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

int main() {
    string s = "";
    cin >> s;
    int n = (int)s.size();
    if ((count(s.begin(), s.end(), 'a') == n/3 || count(s.begin(), s.end(), 'a') == n/3+1) && (count(s.begin(), s.end(), 'b') == n/3 || count(s.begin(), s.end(), 'b') == n/3+1) && (count(s.begin(), s.end(), 'c') == n/3 || count(s.begin(), s.end(), 'c') == n/3+1)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}
 

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <cmath>
#include <cassert>

#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, MOD = 1e9 + 7;

int H, W, dp[1005][1005];
char grid[1005][1005];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> grid[i][j];
        }
    }
    if (dp[1][1] == '#') {
        cout << 0 << '\n';
        return 0;
    }
    dp[1][1] = 1;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (grid[i][j] != '#') (dp[i][j] += dp[i - 1][j] + dp[i][j - 1]) %= MOD;
        }
    }
    cout << dp[H][W] << '\n';
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>s;
    if(s=="Sunny")Cout("Cloudy");
    else if(s=="Cloudy")Cout("Rainy");
    else Cout("Sunny");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,k,a=1;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        if(a<k){
            a*=2;
        }
        else a+=k;
    }
    cout<<a<<endl;
}


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

int main()
{
    int n;
    string s;
    cin>>n;
    cin>>s;
    if(n >= 3200){
        cout<<s<<endl;
    }else{
        cout<<"red"<<endl;
    }

    return 0;
}



Measured memory_bytes: 256
# ABC154d


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 0
    pos = 0

    def cum(array):
        result = [0]
        for i in range(len(array)):
            result.append(array[i]+result[i])
        return result

    def calc(N):
        t = 0
        for i in range(1, N+1):
            t += i / N
        return t

    p2 = cum(p)

    for i in range(n - k+1):
        if ans < p2[i+k]-p2[i]:
            ans = p2[i+k]-p2[i]
            pos = i

    ans = 0
    for i in range(pos, pos + k):
        ans += calc(p[i])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74248
# Setup
import sys
import collections
sys.setrecursionlimit(4100000)

n = int(input())
a = [int(i) for i in input().split()]
d = {}
for i in range(n):
    d[a[i]] = i
ans = ""
for i in range(1,n+1):
    ans += str(d[i]+1) + " "
print(ans)
# print(d)

Measured memory_bytes: 20952
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int x,n;
	cin >> x >> n;
	const int N = 100 + 5;
	int cnt[N] = {};
	rep(i,0,n){
		int y;
		cin >> y;
		++cnt[y];
	}
	int ans = -1;
	rep(i,0,N){
		if(cnt[i] == 0){
			if(abs(i - x) < abs(ans - x)){
				ans = i;
			}
		}
	}
	cout << ans << '\n';
}


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

int main(){
  int d;
  cin >> d;
  vector<int> c(26);
  vector<vector<int>> s(d,vector<int>(26));
  int i,j;
  for(i=0;i<26;i++){
    cin >> c.at(i);
  }
  for(j=0;j<d;j++){
    int max=0,type=0;
    for(i=0;i<26;i++){
      cin >> s.at(j).at(i);
      if(max<=s.at(j).at(i)){
        max=s.at(j).at(i);
        type=i+1;
      }
    }
    cout << type << endl;
  }
}

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

int main() {
	// your code goes here
    /* code */
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++)
{
    cin>>a[i];
}
bool dp[k+1];
memset(dp,0,sizeof(dp));
for(int i=1;i<=k;i++)
{
    for(int j=0;j<n;j++)
    {
        if(a[j]<=i)
        {
            dp[i]|=(!dp[i-a[j]]);
        }
    }
}
if(dp[k]) cout<<"First"<<endl;
else cout<<"Second"<<endl;
return 0;
}


Measured memory_bytes: 512
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var s string
	var y, m, d int
	fmt.Scan(&s)
	slice := strings.Split(s, "/")
	y, _ = strconv.Atoi(slice[0])
	m, _ = strconv.Atoi(slice[1])
	d, _ = strconv.Atoi(slice[2])
	if y <= 2019 && m <= 4 && d <= 30 {
		fmt.Println("Heisei")
	} else {
		fmt.Println("TBD")
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

using namespace std;

int const MAXN = 2005;
struct Edges { int to, next; } e[MAXN], G[MAXN];
int head[MAXN], hhead[MAXN], ttott, tot, f[MAXN][12], dep[MAXN], stk[MAXN], top;
vector <int> D[MAXN];

inline void addedge(int from, int to) {
  e[++tot] = (Edges){to, head[from]};
  head[from] = tot;
}
inline void addedge2(int from, int to) {
  G[++ttott] = (Edges){to, hhead[from]};
  hhead[from] = ttott;
}

void Get(int now, int fa) {
  dep[now] = dep[fa] + 1;
  f[now][0] = fa;
  for (RI i = 1; 1 << i < dep[now]; ++i)
    f[now][i] = f[f[now][i - 1]][i - 1];
  for (RI i = head[now]; i; i = e[i].next)
    if (!dep[e[i].to]) {
      D[now].push_back(e[i].to);
      Get(e[i].to, now);
    }
}
bool Check(int x, int y) {
  for (RI i = 10; ~i; --i)
    if (dep[f[x][i]] >= dep[y])
      x = f[x][i];
  return x == y;
}
void Print(int now) {
  int cnt = 0;
  for (RI i = top; stk[i] != now; --i) ++cnt;
  ++cnt;
  printf("%d\n", cnt);
  while (stk[top] != now) printf("%d\n", stk[top--]);
  printf("%d\n", stk[top]);
  exit(0);
}
void Solve(int now, int mindep) {
  stk[++top] = now;
  for (RI i = hhead[now]; i; i = G[i].next)
    if (G[i].to != f[now][0] && dep[G[i].to] < dep[now] && Check(now, G[i].to))
      mindep = max(mindep, dep[G[i].to]);
  int mmax = -1, node = 0;
  for (RI i = head[now]; i; i = e[i].next)
    if (dep[e[i].to] < dep[now] && Check(now, e[i].to))
      if (dep[e[i].to] > mindep)
        if (dep[e[i].to] > mmax)
          mmax = dep[e[i].to], node = e[i].to;
  if (mmax != -1) Print(node);
  for (auto i : D[now])
    Solve(i, mindep);
  --top;
}

int main() {


  int n, m; scanf("%d %d", &n, &m);
  for (RI i = 1, x, y; i <= m; ++i)
    scanf("%d %d", &x, &y), addedge(x, y), addedge2(y, x);
  for (RI i = 1; i <= n; ++i) {
    for (RI j = 1; j <= n; ++j) D[j].clear();
    memset(dep, 0, sizeof(dep));
    memset(f, 0, sizeof(f));
    Get(i, 0);
    Solve(i, 0);
  }
  puts("-1");
  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 640
#!/usr/bin/env python3
from sys import stdin

def solve():
    n, k = map(int, stdin.readline().split())
    items = []
    for i in range(n):
        items.append(int(stdin.readline().strip()))

    items = sorted(items)
    ans = 10**9
    for i in range(n-k+1):
        diff = items[i+k-1] - items[i]
        if diff<ans:
            ans = diff

    print(ans)

solve()

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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  long int n,k,i,at=0;
  cin>>n>>k;
	long int h[n];
  for(i=0; i<n; i++)
    cin>>h[i];
  
  sort(h, h+n);
  
  if(k>=n)
    cout<<0;
  
  else{
    for(i=0; i<n-k; i++)
      at=at+h[i];
    cout<<at;
  }
  return 0;
}


Measured memory_bytes: 1792
fun isInteger(value: Double): Boolean {
    return Math.ceil(value) == Math.floor(value)
}

fun main(args: Array<String>) {
    val (n, d) = readLine()!!.split(" ").map(String::toInt)
    var values = Array(n) { IntArray(d) }

    for (i in 0 until n) {
        val line = readLine()!!.split(" ").map(String::toInt)
        for (j in 0 until d) {
            values[i][j] = line[j]
        }
    }

    var count = 0;
    for (i in 0 until n) {
        for (j in i+1 until n) {
            if (i == j) continue

            var value = 0;
            for (k in 0 until d) {
                val v = values[i][k] - values[j][k]
                value += v*v
            }

            val result = Math.sqrt(value.toDouble())
            if (isInteger(result)) {
                count++
            }

        }
    }

    println(count)
}

Measured memory_bytes: 37752