akhauriyash/Code-Regression huggingface dataset:
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;
	using BigNum = std::vector<long long>;

	class InputData {
	public:
		void getInput(void);
		void skipInput(void);
		Str getStr(void);
		Num getNum(void);
		BigNum getBigNum(void);
	private:
		Str str;
		Num num;
		BigNum bNum;
	};
	Str AtCoder::InputData::getStr(void) {
		return this->str;
	}
	Num AtCoder::InputData::getNum(void) {
		return this->num;
	}
	BigNum AtCoder::InputData::getBigNum(void) {
		return this->bNum;
	}
	void AtCoder::InputData::skipInput(void) {
		std::string buf = "";
		std::getline(std::cin, buf);
	}
	void AtCoder::InputData::getInput(void) {
		this->str.clear();
		this->num.clear();
		this->bNum.clear();

		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				this->str.push_back(row);
				this->num.push_back(std::atoi(row.c_str()));
				this->bNum.push_back(std::atoll(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		this->str.push_back(row);
		this->num.push_back(std::atoi(row.c_str()));
		this->bNum.push_back(std::atoll(row.c_str()));
	}

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(long long);
		void decrement(void);
		void decrement(long long);
		long long getResult(void);
	private:
		long long result;
	};
	void Ans::showResult(void) {
		printf("%lld\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(long long value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(long long value) {
		this->result -= value;
	}
	long long AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::InputData* data = new AtCoder::InputData();
	data->getInput();

	AtCoder::Num num = data->getNum();

	const int A = num[2], B = num[0], C = num[1];

	printf("%d %d %d\n", A, B, C);

	delete(data);

	return 0;
}


Measured memory_bytes: 256
X,Y,Z,K=gets.split.map(&:to_i)
as=gets.split.map(&:to_i).sort
bs=gets.split.map(&:to_i)
cs=gets.split.map(&:to_i)
bcs=Array.new
for i in 0...Y
    for j in 0...Z
        bcs << bs[i]+cs[j]
    end
end
bcs.sort!
bcs.reverse!
bcs=bcs[0,K]
abcs=Array.new
for i in 0...bcs.size
    for j in 0...X
        abcs << bcs[i]+as[j]
    end
end
puts abcs.sort.reverse[0,K]


Measured memory_bytes: 94060
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		if (Math.abs(n - m) <= 1) {
		    long ans = kaijo(n) * kaijo(m);
		    ans %= MOD;
		    if (n == m) {
		        ans *= 2;
		        ans %= MOD;
		    }
		    System.out.println(ans);
		} else {
		    System.out.println(0);
		}
	}
	
	static long kaijo(long x) {
	    long ans = 1;
	    for (int i = 1; i <= x; i++) {
	        ans *= i;
	        ans %= MOD;
	    }
	    return ans;
	}
}


Measured memory_bytes: 23124
#include<iostream>

using namespace std;
#define FLASH ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long 
 
int32_t main()
{
 FLASH;
 int a,b;
 cin>>a>>b;
 int ans=0;
 int count=1;
 while(count<b)
 {
    count +=(a-1);
    ++ans;
 }
 
 cout<<ans<<endl;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,-1,1,1,-1};
int dy[]={0,1,0,-1,-1,-1,1,1};


vector<LL> divi(LL K){
    vector<LL> v;
    for(LL i=1;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        v.pb(K/i);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)),v.end());
    return v;
}

bool p[1000001];

int main(){
    LL n;cin >> n;
    vector<int> a(n);
    map<int,int> ma;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        p[a[i]] = true;
        ma[a[i]]++;
    }
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        auto d = divi(a[i]);
        bool s = true;
        for (int j = 0; j < d.size(); j++) {
            if(d[j] == a[i]) continue;
            if(p[d[j]]){
                s = false;
                break;
            }
        }
        if(s and ma[a[i]] == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int r, c; cin >> r >> c;
    vvi h(r+1, vi(c+1)); REP(i, r) REP(j, c) cin >> h[i][j];
    REP(i, r)
    {
        int sum = 0;
        REP(j, c) sum += h[i][j];
        h[i][c] = sum;
    }
    REP(i, c+1)
    {
        int sum = 0;
        REP(j, r) sum += h[j][i];
        h[r][i] = sum;
    }
    REP(i, h.size())
    {
        REP(j, h[i].size()) 
        {
            cout << h[i][j];
            if(j != h[i].size()-1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3244
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */
int dp[10010];
int ret[10010];
const int num[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
    int n, m, a_[20];
    scanf("%d%d", &n, &m);
    rep(i, m) scanf("%d", &a_[i]);
    vector<int> a;
    rep(i, m) a.pb(a_[i]);
    sor(a);
    rev(a);

    dp[0] = 0;
    rep1(i, n) {
        dp[i] = -INF;
        rep(j, m) {
            int nu = num[a[j]];
            if (i - nu < 0)
                continue;
            dp[i] = max(dp[i], dp[i - nu] + 1);
        }
    }
    int keta = dp[n];
    int mat = n;
    rep(i, keta) {
        rep(j, m) {
            int nu = num[a[j]];
            if (mat - nu >= 0 && dp[mat - nu] == dp[mat] - 1) {
                ret[i] = a[j];
                mat -= nu;
                break;
            }
        }
    }
    rep(i, keta) {
        printf("%d", ret[i]);
    }

    printf("\n");

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
            #include <ext/pb_ds/assoc_container.hpp>
            #include <ext/pb_ds/tree_policy.hpp>
            using namespace std;
            using namespace __gnu_pbds;
            #define rep(i, a , b) for (ll i =a ; i < b ; i++)
            #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            #define endl "\n"
            #define pb push_back
            #define F first
            #define S second
            #define print(a)       for(auto x : a) cout << x << " "; cout << endl
            #define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
            #define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
            #define mk(x,y)  make_pair(x,y)
            typedef long long int ll;
            const ll N =  3e3+5;
            const ll mod = 1e9+7;
            const ll inf = 1e18;
            ll   n ,x ,c, y  , k  , m  , l , r , u , z , d   , a[N][N] , dp[N][N][4];

    ll pow_mod_m(ll a , ll n)
    {
        if(!n)
            return 1;
        ll pt =  pow_mod_m(a,n/2) ;
        pt *= pt  , pt %= mod;
        if(n&1)
            pt *= a , pt %= mod;
        return pt;
    }

    int main()
    {
         IOS;
         int ts =1;
         ///cin >> ts ;
         while( ts-- )
         {
            cin >> n >> m >> k;
            rep(i,1,k+1)
            {
                cin >> l >> r >> d;
                a[l][r] = d;
            }
            for(int i= n; i>=1 ; i--)
            {
                for(int j = m; j>= 1; j--)
                {
                    dp[i][j][1] = max({a[i][j] , dp[i][j+1][1] , max( { dp[i+1][j][1] , dp[i+1][j][2] , dp[i+1][j][3]  } ) + a[i][j]});
                    dp[i][j][2] = max( dp[i][j+1][2] , a[i][j] + dp[i][j+1][1]  );
                    dp[i][j][3] = max( dp[i][j+1][3] , dp[i][j+1][2] + a[i][j] );
                }
            }
            cout << max( {  dp[1][1][1] , dp[1][1][2] , dp[1][1][3] } );
         }
    }


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

class Node(object):
    def __init__(self, N):
        self.parent = [-1 for i in range(N)]
        self.left = [-1 for i in range(N)]
        self.right = [-1 for i in range(N)]
        self.depth = [-1 for i in range(N)]
        self.sibling = [-1 for i in range(N)]
        self.height = [0 for i in range(N)]
        self.degree = [0 for i in range(N)]

    def set_depth(self, u):
        d, U = 0, u
        while T.parent[u] is not -1:
            u = T.parent[u]
            d += 1
        self.depth[U] = d

    def set_height(self, u):
        h1 = h2 = 0
        if self.left[u] is not -1:
            h1 = self.set_height(self.left[u]) + 1
        if self.right[u] is not -1:
            h2 = self.set_height(self.right[u]) + 1
        
        self.height[u] = max(h1, h2)
        return max(h1, h2)
            

N = int(input())

# create node
T = Node(N)

# set data
for j in range(N):
    A = [int(i) for i in input().split()]

    # left???right????±????
    T.left[A[0]] = A[1]
    T.right[A[0]] = A[2]
    
    # parent???degree????±????
    for u in A[1:]:
        if u is not -1:
            T.parent[u] = A[0]
            T.degree[A[0]] += 1
            
    # sibling????±????
    if (A[1] is not -1) and (A[2] is not -1):
        T.sibling[A[1]], T.sibling[A[2]] = A[2], A[1]

# set depth
for i in range(N):
    T.set_depth(i)

# set height
T.set_height(T.parent.index(-1))

# ??????
for i in range(N):
    # ?????????????¨?????????????
    if T.parent[i] is -1:
        node = "root"
    elif T.left[i] is -1 and T.right[i] is -1:
        node = "leaf"
    else:
        node = "internal node"

    print("node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, height = {5}, {6}".format(i, T.parent[i], T.sibling[i], T.degree[i], T.depth[i], T.height[i], node))

Measured memory_bytes: 7876
#include<cstdio>
#include<cctype>
#include<map>
#define For(i,j,k) for(int i=j;i<=k;i++)
int read(){
	int x=0,l=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') l=-1; ch=getchar();}
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	return x*l;
}using namespace std;
map<int,int> mp;

int main(){
	int n=read(),x,m;
	For(i,1,n) mp[read()]++;
	m=read();
	For(i,1,m){
		x=read(); if (mp[x]>0) mp[x]--;
		else {printf("NO\n"); return 0;}
	}
	printf("YES\n");
	return 0;
}

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

template<class T>
void chmin(T &a, T b)
{
	if (a > b) a = b;
}

ll N;
vector<ll> h;
ll dp[100010];

int main(int argc, char **argv)
{
	cin >> N;
	h.resize(N); for (ll i = 0; i < N; ++i) cin >> h[i];

	for (ll i = 0; i < 100010; ++i) dp[i] = (1<<30);

	dp[0] = 0;
	for (ll i = 0; i < N; ++i)
	{
		chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
		chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
	}
	std::cout << dp[N-1] << std::endl;
}

Measured memory_bytes: 1792
n,*a=map(int,open(0).read().split())
cnt=1
for i in range(n):
  if a[i]==cnt:
    cnt+=1
if n>1:
  if cnt>1:
    print(n-cnt+1)
  else:
    print(-1)
else:
  if a[0]==1:
    print(0)
  else:
    print(-1)

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

int main() {
  char c;cin>>c;
  if('a'<=c)cout<<'a'<<endl;
  else cout<<'A'<<endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
  int n,d;
  cin >> n >> d;
  int i,j,k;
  int cnt = 0;
  double sum = 0;
  vector<vector<int>> a(n,vector<int>(d));
  for(i=0;i<n;i++) {
    for(j=0;j<d;j++) cin >> a[i][j];
  }
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      double sum = 0;
      for(k=0;k<d;k++){
        sum += pow(a[i][k]-a[j][k] , 2);
      }
      if(ceil(sqrt(sum))==floor(sqrt(sum))) cnt++;
    }
  }
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

import itertools as it
ans = 0
for a,b,c in it.product(range(A+1), range(B+1), range(C+1)):
    if 500*a + 100*b + 50*c == X:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<queue>

using namespace std;

typedef struct{
  int x;
  int y;
}Point;

int main(){

  Point goal;
  while(cin >> goal.x >> goal.y && goal.x + goal.y){
    int sum = 0;
    int data[goal.y+1][goal.x+1];
    for(int i = 0; i <= goal.y; i++){
      for(int j = 0; j <= goal.x; j++){
      	data[i][j] = 1;
     }
    }
    int num;
    cin >> num;
    for(int i = 0; i < num; i++){
      int a,b;
      cin >> a >> b;
      data[b][a] = 0;
    }

    queue<Point> Q;
    Point init;
    init.x = init.y = 1;
    Q.push(init);
    while(!Q.empty()){
      Point now = Q.front();
      Q.pop();
      if(now.x == goal.x && now.y == goal.y){
	sum++;
	continue;
      }
      if(now.x < goal.x){
	if(data[now.y][now.x+1]){
	  Point next;
	  next.x = now.x+1;
	  next.y = now.y;
	  Q.push(next);
	}
      }
      if(now.y < goal.y){
	if(data[now.y+1][now.x]){
	  Point next;
	  next.x = now.x;
	  next.y = now.y+1;
	  Q.push(next);
	}
      }
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 7164
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

vector<vector<int>>g;
void dfs(int v,int p,vector<int>& a) {
    if(v != p)a[v] += a[p];
    for(int nv : g[v]) {
        if(nv == p) continue;
        dfs(nv,v,a);
    }
}
int main() {
    int n,q;
    cin >> n >> q;
    g.assign(n,vector<int>());
    rep(i,n-1) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> point(n);
    rep(i,q) {
        int p,x;
        cin >> p >> x;
        p--;
        point[p] += x;
    }
    dfs(0,0,point);
    rep(i,n) cout << point[i] << " ";
    cout << endl;
}

Measured memory_bytes: 23424
#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;

const int MOD = 1000000007;


int main() {
    string S;
    cin >> S;
    int N = S.size();
    vector<vector<ll>> dp(N+1, vector<ll>(13,0));
    dp[0][0] = 1;

    REP(i,N){
        if(S[i] != '?'){
            REP(j,13){
                int next = (j*10+(S[i]-'0')) % 13;
                dp[i+1][next] += dp[i][j];
                dp[i+1][next] %= MOD;
            }
        }else{
            REP(j,13){
                REP(k,10){
                    int next = (j*10+k) % 13;
                    dp[i+1][next] += dp[i][j];
                    dp[i+1][next] %= MOD;
                }
            }
        }
    }
    cout << dp[N][5] << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  int h,w;cin>>h>>w;
  rep(i,h)rep(j,w){
    string s;cin>>s;
    if(s=="snuke"){
      cout<<(char)('A'+j)<<i+1<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
# solution
# online help taken

h,w=map(int,input().split())
ans=h*w

if h%3==0 or w%3==0:
  ans=0
else:
  ans=min(h,w)
  
a=round(h/3)*w
b=(h-round(h/3))*(w//2)
c=h*w-a-b
d=max(a,b,c)-min(a,b,c)
ans=min(ans,d)
a=round(w/3)*h
b=(w-round(w/3))*(h//2)
c=h*w-a-b
d=max(a,b,c)-min(a,b,c)
ans=min(ans,d)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
int main()
{
    ll x;
    bool flag = false;
    std::cin >> x;
    if (x >= 30) {
        flag = true;
    }
    if (flag) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

struct Team{
    int solve;
    int time;
    int id;
    vector<int> wa;
    vector<bool> solved;
    Team(int P){
        solve = time = 0;
        solved.resize(P);
        wa.resize(P);
    }
    bool operator < (const Team& t) const {
        if(solve != t.solve) return solve > t.solve;
        if(time != t.time)  return time < t.time;
        return id > t.id;
    }
};

int main(){
    int M, T, P, R;
    while(cin >> M >> T >> P >> R && M > 0) {
        vector<Team> teams(T, Team(P));
        REP(i, T) teams[i].id = i + 1;

        REP(i, R) {
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            t--;
            p--;
            if(j == 0) {
                if(teams[t].solved[p]) continue;
                teams[t].solved[p] = true;
                teams[t].time += 20 * teams[t].wa[p] + m;
                teams[t].solve += 1;
            } else {
                teams[t].wa[p] += 1;
            }
        }

        sort(teams.begin(), teams.end());

        for(int i = 0; i < T; i++) {
            if(i > 0) {
                if(teams[i - 1].solve == teams[i].solve && teams[i - 1].time == teams[i].time) {
                    cout << "=";
                } else {
                    cout << ",";
                }
            }
            cout << teams[i].id;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define x first
#define y second
#define N 100050
using namespace std;
typedef pair<int,int> pii;
map<pii,int> mp;
vector<int> e[N];
queue<pii> q;
int fa[N],siz[N],tot,n;

pii MP(int a,int b) {if (a>b) swap(a,b); return make_pair(a,b);}

inline int rd() {int r;scanf("%d",&r);return r;}

void link(int a,int b) {
	e[a].push_back(b);
	e[b].push_back(a);
	mp[MP(a,b)]++;
}

int gf(int u) {return fa[u]==u?u:gf(fa[u]);}

int main() {
	n = rd();
	for (int i=1;i<=n;i++) fa[i] = i;
	for (int i=1;i<=2*n-2;i++) link(rd(), rd());
	
	for (map<pii,int>::iterator it=mp.begin();it!=mp.end();it++)
		if (it->y == 2) q.push(it->x);
		
	while (!q.empty()) {
		pii u = q.front(); q.pop();
		int a = gf(u.x), b = gf(u.y);
		if (a == b) continue;
		++tot;
		if (siz[a] < siz[b]) swap(a, b);
		for (int i=0;i<(int)e[b].size();i++) {
			int t=gf( e[b][i] );
			if (t == a) continue;
			e[a].push_back(t);
			mp[ MP(b, t) ]--;
			mp[ MP(a, t) ]++;
			if (mp[ MP(a, t) ] == 2) q.push( MP(a, t) ); 
		}
		e[b].clear();
		fa[b] = a;
	}
	
	puts(tot==n-1?"YES":"NO");	
	return 0;
}

Measured memory_bytes: 117300
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

alias Rect = Tuple!(int, "left", int, "right");

int calc(Rect a, Rect b) {
    if (a.left > b.left) return calc(b, a);

    return max(0, b.left - a.right);
}

void main() {
    auto wab = readints;
    int w = wab[0], a = wab[1], b = wab[2];

    auto r1 = Rect(a, a + w);
    auto r2 = Rect(b, b + w);
    writeln(calc(r1, r2));
}


Measured memory_bytes: 256
N=input()
if N=='SUN':
  print("7")
if N=='MON':
  print("6")
if N=='TUE':
  print("5")
if N=='WED':
  print("4")
if N=='THU':
  print("3")
if N=='FRI':
  print("2")
if N=='SAT':
  print("1")


Measured memory_bytes: 38256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>
#include <numeric>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int gcd(int m, int n)
{
    if(m < n) return gcd(n,m);
    if(n == 0) return m;
    return gcd(n, m % n);
}

int main(void)
{
    int n;
    cin >> n;
    vector<int> a;
    int l[200000], r[200000];
    int maxval = 0;
    REP(i,n)
    {
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    l[0] = a[0];
    r[n-1] = a[n-1];
    for(int i = 1;i< n;i++)
    {
        l[i] = gcd(l[i-1],a[i]);
    }
    for(int i = n - 2;i >= 0;i--)
    {
        r[i] = gcd(a[i],r[i+1]);
    }
    REP(i,n)
    {
        if(0 < i && i < n - 1)
        {
            maxval = max(maxval, gcd(l[i-1],r[i+1]));
        }
        else if(i==0)
        {
            maxval = max(maxval, r[i+1]);
        }
        else
        {
            maxval = max(maxval, l[i-1]);
        }
        
    }
    cout << maxval << endl;
}


Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
#define FASTINPUT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) 
#define ll long long 
#define mp make_pair
#define pb push_back
#define Ma 1000000007

int main(){
  FASTINPUT;
  //#ifndef ONLINE_JUDGE
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  //#endif
   ll t;
   t=1;
   while(t>0)
   {
    ll n,q,i;
    cin>>n>>q;
    string s;
    cin>>s;
    ll ans[n+1];
    bool yes[n+1];
    memset(ans,0,sizeof(ans));
    memset(yes,false,sizeof(ans));
    for(i=0;i<s.length()-1;i++)
    {
      if(s[i]=='A'&&s[i+1]=='C')
    {
        ans[i]=1;
        yes[i]=true;
      }
      else
        ans[i]=0;
    }
    for(i=1;i<n;i++)
    {
      ans[i]+=ans[i-1];
    }
    while(q>0)
    {
      ll l,r;
      cin>>l>>r;
      l--;
      r--;
      ll x;
      
      if(l!=0)
      x=ans[r]-ans[l-1];
    else
      x=ans[r];
    if(yes[r]==true)
      x--;
    cout<<x<<endl;

      q--;
    }

    t--;
   }
  
 return 0; 
    
}

           

Measured memory_bytes: 2000
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s, S, ES;
  int LONGS;
  
  S = 's';
  ES = "es";
  
  cin >> s;
  
  LONGS = (int) s.size();
  
  if(s[LONGS-1] == 's') s += ES;
  else s += S;
  
  cout << s << endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

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

    long long totalTime = t;
    int beforeTime;
    cin >> beforeTime;
    for( int i = 1;i < n;++i )
    {
        int currentTime;
        cin >> currentTime;

        totalTime += t;
        int diff = t - ( currentTime - beforeTime );
        if( diff > 0 )
            totalTime -= diff;
        beforeTime = currentTime;
    }
    cout << totalTime << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll a, p;
    cin >> a >> p;
    cout << (3 * a + p) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
L = input().split()
tri = 0
for i in range(0,N):
    L[i] = int(L[i])
L.sort()
for i in range(0,N):
    k = i
    for j in range(i+1,N):
        while(k < N and L[k] < L[i] + L[j]):
            k += 1
        tri += k-j-1
print(tri)

Measured memory_bytes: 3188
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  endl           "\n"
#define  pb             push_back
#define  sym(s)         s="#"+s+"#";
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());

typedef  long long             ll;
typedef  unsigned long long    ull;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  998244353;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  3e+5+7;

vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n,k;
ll l[15],r[15];
ll dp[N],pre[N];
//<<-----Implement Functions Here---->>//
ll add(ll a,ll b){
	return (a%MOD + b%MOD)%MOD;
}
ll mult(ll a,ll b){
	return (a%MOD * b%MOD)%MOD;
}
ll subt(ll a,ll b){
	return (a%MOD - b%MOD + MOD)%MOD;
}

//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n>>k;
		for(ll i=1;i<=k;i++)cin>>l[i]>>r[i];
		dp[0] = 0;dp[1] = 1;

		for(ll i=1;i<=n;i++)
		{
			for(ll j=1;j<=k;j++)
			{
				ll l1 = max(i-l[j],ll(0));ll r1 = max(i-r[j],ll(1));
				dp[i] = add(dp[i],subt(pre[l1],pre[r1-1]));
			}
			pre[i] = add(pre[i],add(pre[i-1],dp[i]));
			//for(ll i=1;i<=n;i++)cout<<dp[i]<<" ";cout<<endl;
			//for(ll i=1;i<=n;i++)cout<<pre[i]<<" ";cout<<endl;
		}
		
		cout<<dp[n]<<endl;

		
}

int main(){
    fastio;randomINIT;

    //cin>>t;
    while(t--){
        MAIN();
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}

Measured memory_bytes: 13816
def gcd_ex(x, y)
  if y == 0 then
    return [x, 0]
  else
    res = gcd_ex(y, x % y)
    res[1] += 1
    return res
  end
end

while (inputs = gets.split)[0] != "0"
  a = inputs[0].to_i
  b = inputs[1].to_i

  if a < b then
    tmp = a
    a = b
    b = tmp
  end

  puts gcd_ex(a, b).join(" ")
end

Measured memory_bytes: 2700
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<climits>
#include<algorithm>
#include<functional>
#include<iomanip>
#define LL long long
using namespace std;

int n,m,sum,cheese[15][2],sx,sy,gx,gy,book[1010][1010],dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
char a[1010][1010];

struct node{
    int x,y,step;
}t1,t2;

queue<struct node> q;

bool judge(int x,int y){
    if(x>=0 && x<n && y>=0 && y<m && !book[x][y] && a[x][y]!='X') return true;
    return false;
}

int bfs(void){
    if(sx==gx && sy==gy) return 0;
    while(!q.empty()) q.pop();
    t1.x=sx;
    t1.y=sy;
    t1.step=0;
    book[sx][sy]=1;
    q.push(t1);
    while(!q.empty()){
        t1=q.front();
        q.pop();
        t2.step=t1.step+1;
        int i;
        for(i=0;i<4;i++){
            t2.x=t1.x+dir[i][0];
            t2.y=t1.y+dir[i][1];
            if(t2.x==gx && t2.y==gy) return t2.step;
            if(judge(t2.x,t2.y)){
                    book[t2.x][t2.y]=1;
                    q.push(t2);
            }
        }
    }
}

int main(void){
    scanf("%d %d %d",&n,&m,&sum);
    int i,j;
    for(i=0;i<n;i++) scanf("%s",a[i]);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            if(a[i][j]=='S'){
                cheese[0][0]=i;
                cheese[0][1]=j;
            }
            if(a[i][j]>='1' && a[i][j]<='9'){
                cheese[a[i][j]-'0'][0]=i;
                cheese[a[i][j]-'0'][1]=j;
            }
        }
    }
    int ans=0;
    for(i=0;i<sum;i++){
        memset(book,0,sizeof(book));
        sx=cheese[i][0];sy=cheese[i][1];
        gx=cheese[i+1][0];gy=cheese[i+1][1];
        ans+=bfs();
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 8172
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N, Q;
ll A[100000], X[100000];
ll sum[100001] ={}, ssum[100000];

signed main(){
    cin >> N >> Q;
    rep(i, N) cin >> A[i];
    rep(i, Q) cin >> X[i];
    for(int i=N-1; i>=0; i--) sum[i] = A[i]+sum[i+1];
    ssum[0] = A[0]; ssum[1] = A[1];
    for(int i=2; i<N; i++) ssum[i] = ssum[i-2] + A[i];

    rep(i, Q){
        int ok = (N+1)/2;
        int ng = 0;
        while(ok-ng > 1){
            int m = (ng+ok)/2;
            if(X[i]-A[N-2*m-1] > A[N-m-1]-X[i]) ok = m;
            else ng = m;
        }
        //cout << ok << " " << sum[N-ok] << " " << (N-2*ok-1 >= 0 ? ssum[N-2*ok-1] : 0) << endl;
        cout << sum[N-ok] + (N-2*ok-1 >= 0 ? ssum[N-2*ok-1] : 0) << endl;
    }
}

Measured memory_bytes: 6756
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    string s;
    cin >> s;
    string ans = "";
    for(int i = 0; i < s.size(); i += 2) {
        ans += s[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#define REP(i,a,b) for (i=(a); i<(b); ++i)
#define rep(i,n) REP(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
double a[101][101];
double memo[101][101][101];

double solve(int n, int m, int k, int p)
{
    double res;
    int i, j;
    if (m == 1) return 1;
    if (memo[m][k][p] > 0) return memo[m][k][p];
    res = 0;
    rep(i, n) res = MAX(res, solve(n, m-1, p, i) * a[p][i]);
    return memo[m][k][p] = res;
}

int main(void)
{
    int n, m, i, j, k;
    double res;
    while (scanf("%d%d",&n,&m),n|m) {
        memset(memo, 0, sizeof(memo));
        rep(i, n) rep(j, n) scanf("%lf", &a[i][j]);
        res = 0;
        rep(i, n) rep(j, n) res = MAX(res, solve(n, m, i, j));
        printf("%.2f\n", res);
    }

    return 0;
}

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

using P = pair<int, int>;
int k, t;
priority_queue<P> pq;

int main() {
  cin >> k >> t;
  for (int i = 0; i < t; ++i) {
    int a;
    cin >> a;
    pq.push(P(a, i));
  }
  int bf = -1, res = 0;
  for (int i = 0; i < k; ++i) {
    P now = pq.top();
    pq.pop();
    if (now.second == bf && pq.size()) {
      P dummy = pq.top();
      pq.pop();
      pq.push(now);
      now = dummy;
    }
    res += now.second == bf;
    bf = now.second;
    if (--now.first > 0) pq.push(now);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3548
#include <iostream>

int main(){
    int x, y;

    std::cin >> x >> y;

    for (int i = 0; i <= x; i++)
    {
        if (4 * i + 2 * (x - i) == y)
        {
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
    
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
 using namespace std;
int main() {
  int N, X;
  int L[100]={} , D[101]={} ;
 cin >> N >> X;
  int counter = 0;
  for (int i=0; i<N+1; i++) {
    cin >> L[i];
    if (D[i]<=X) {
      counter++;
    }
    else {
      break;
    }
    D[i+1] = D[i] + L[i];
  }
cout << counter << std::endl;

}


Measured memory_bytes: 256
def solve(h, w, A, B):
    center = 80 * (h + w - 1)
    C = [[abs(A[r][c] - B[r][c]) for c in range(w)] for r in range(h)]
    dp = [[0] * w for r in range(h)]
    dp[0][0] = (1 << (center + C[0][0])) | (1 << (center - C[0][0]))
    for r in range(h):
        for c in range(w):
            if r > 0:
                dp[r][c] |= (dp[r-1][c] << C[r][c]) | (dp[r-1][c] >> C[r][c])
            if c > 0:
                dp[r][c] |= (dp[r][c-1] << C[r][c]) | (dp[r][c-1] >> C[r][c])
    mask = bin(dp[-1][-1] >> center)
    return mask[::-1].find("1")
h, w = map(int, input().split())
A = [list(map(int, input().split())) for i in range(h)]
B = [list(map(int, input().split())) for i in range(h)]
print(solve(h, w, A, B))


Measured memory_bytes: 57052
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    void solve()
    {
        string[] str = Console.ReadLine().Split(' ');
        int A = int.Parse(str[0]);
        int B = int.Parse(str[1]);
        int C = int.Parse(str[2]);
        int D = int.Parse(str[3]);

        if (A < C) A = C;
        if (B > D) B = D;

        if (A > B) A = 0;
        else A = B - A;

        Console.WriteLine(A);
    }

    public static int Main()
    {
        bool loop = false;
#if ES_DEBUG
        loop = true;
#endif
        do
        {
            new Program().solve();
        } while (loop);
        return 0;
    }
}


Measured memory_bytes: 11092
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#define se cout << "test ok" << endl;
#define sp << " " <<
#define enl "\n"
using namespace std;
using ll=long long;
using ld=long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using vlll = vector<vector<vector<ll>>>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
ll mod = ll(1e9)+7;
ll inf = ll(1e18);
void bl(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void bl2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

namespace dbg {
    using ll = long long;

    class Debug {
    public:
        Debug(){}
        template<typename T>
        void vd(vector<T> vec);
        template<typename T>
        void vd2(vector<vector<T>> vec);
        template<typename T>
        void ad(T *arr, ll n);
        template<typename T, size_t N>
        void ad2(T (&arr)[N], ll n);
        template<typename T>
        void md(T mp);
    };

    template<typename T>
    void Debug::vd(vector<T> vec) {
        for (auto vv : vec) cout << vv << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::vd2(vector<vector<T>> vec) {
        for (auto vv : vec) {
            for (auto vvv : vv) cout << vvv << " ";
            cout << endl;
        }
    }

    template<typename T>
    void Debug::ad(T *arr, ll n) {
        for (int i = 0; i <= n; i++) cout << arr[i] << " ";
        cout << endl;
    }

    template<typename T, size_t N>
    void Debug::ad2(T (&arr)[N], ll n) {
        for (int i = 0; i <= N; i++) for (int j = 0; j <= n; j++) cout << arr[i][j] << " ";
        cout << endl;
    }

    template<typename T>
    void Debug::md(T mp) {
        cout << "key : value" << endl;
        for (auto const &m : mp) cout << m.first << " : " << m.second << endl;
        cout << endl;
    }

}

#endif //INCLUDE_DEBUG_HPP

dbg::Debug debug;

class BBattle {
public:
	void solve(std::istream& in, std::ostream& out) {
		ll a, b, c, d;
		in >> a >> b >> c >> d;

		bool taka = true;
		while(a > 0 && c > 0){
			if(taka){
				c -= b;
			}else{
				a -= d;
			}
			taka = !taka;
		}

		if(a <= 0) out << "No" << enl;
		else out << "Yes" << enl;
	}
};


int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	BBattle solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3644
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C
import Data.List

main = do
    [n,k] <- unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine
    h <- U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

    let dp = U.constructN n (\dp_ ->
            if U.null dp_ then 0
                else let i = U.length dp_
                         hi = h U.! i
                         f = U.slice (max 0 (i-k)) (min i k)
                         refh = f h
                         refd = f dp_
                    in U.minimum (
                        U.zipWith (\dc hc -> dc + abs(hi - hc)) refd refh
                        )
            )

    print $ U.last dp


Measured memory_bytes: 3708
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> d(K);
    vector<vector<int>> A;
    REP(i, 0, K){
        cin >> d[i];
        int in;
        vector<int> tmp;
        REP(j, 0, d[i]){
            cin >> in;
            tmp.push_back(in);
        }
        A.push_back(tmp);
    }

    vector<int> sunuke(N, 1) ;
    REP(i, 0, K){
        for (auto a: A[i]){
            sunuke[a - 1] = 0;
        }
    }
    int sum = 0;
    REP(i, 0, N){
        sum += sunuke[i];
    }
    cout << sum << endl;

    return 0;
}


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

int main(){
  int k;
  cin>>k;
  long long int sum = 0;
  for(int i = 1;i <= k;i++){
    for(int j = 1;j <= k;j++){
      for(int l = 1;l<=k;l++)
        sum+=__gcd(__gcd(i,j),l);
    }
  }
  
  cout<<sum<<"\n";
  return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    public static void Main(string[] args)
    {
        var list = new List<string>() { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
        var val = Console.ReadLine();
        var idx = list.IndexOf(val);
        Console.WriteLine(7 - idx);
    }
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  vector<int> p(n); for(int i = 0; i < n; ++i) cin >> p[i];
  int sum = 0;
  sort(p.begin(), p.end());
  for(int i = 0; i < n; i++) {
    if(i == n-1) sum += p[i] / 2;
    else sum += p[i];
  }
  cout << sum << endl;

  return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
int main(){
	double a[3][3];
	double x;
	int b;
	while(scanf("%lf %lf %lf %lf %lf %lf",&a[0][0],&a[0][1],&a[0][2],&a[1][0],&a[1][1],&a[1][2])!=EOF){
		a[0][1]/=a[0][0];
		a[0][2]/=a[0][0];
		a[0][0]/=a[0][0];
		x=a[1][0]/a[0][0];
		a[1][0]-=x*a[0][0];
		a[1][1]-=x*a[0][1];
		a[1][2]-=x*a[0][2];
		a[1][2]/=a[1][1];
		a[1][0]/=a[1][1];
		a[1][1]/=a[1][1];
		x=a[0][1]/a[1][1];
		a[0][0]-=x*a[1][0];
		a[0][1]-=x*a[1][1];
		a[0][2]-=x*a[1][2];
		printf("%.3f %.3f\n",a[0][2],a[1][2]);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
        int sheep = in.nextInt();
        int wolves = in.nextInt();
        if(wolves >= sheep)
        {
            System.out.println("unsafe");
        }
        else
        {
            System.out.println("safe");
        }
    }
}


Measured memory_bytes: 35696
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: ringring
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  printf("%d\n", a + b + c - max(a, max(b, c)));
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	//b-a のたかさ−１までの和が左の枝の高さ
	dif := b - a
	left := 0
	for i := 1; i < dif; i++ {
		left += i
	}
	fmt.Println(left - a)
}

Measured memory_bytes: 512
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N, M;
	cin >> N >> M;
	
	string S;
	cin >> S;
	
	reverse(S.begin(), S.end());
	vector< int > A;
	for (int i=0; i<=N; ++i) if (S[i] == '0') A.push_back(i);
	
	int cur = 0;
	vector< int > ans;
	
	while (A[cur] < N) {
		int d = 0;
		while (A[cur] < N && d + A[cur + 1] - A[cur] <= M) {
			d += A[cur + 1] - A[cur];
			++cur;
		}
		
		if (d == 0) {
			puts("-1");
			return 0;
		}
		
		ans.push_back(d);
	}
	
	reverse(ans.begin(), ans.end());
	for (int i=0, n=ans.size(); i<n; ++i) cout << ans[i] << (i<n-1 ? " " : "\n");
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 1592
n = int(input())
s = set()
w = input()
last = w[-1]
s.add(w)
for i in range(n - 1):
  w = input()
  if w in s or w[0] != last:
    print('No')
    exit()
  else:
    last = w[-1]
    s.add(w)
print('Yes')

Measured memory_bytes: 9088