akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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;
}

class Dijkstra {
  private:
    struct Graph {
        int to, cost;
    };
    int V;
    vector<vector<Graph>> G;
    const long long INF = 4'000'000'000'000'000'000;
    using P             = pair<long long, int>;
    vector<long long> dist;

  public:
    Dijkstra(int v) {
        V = v;
        G.resize(v);
        dist.resize(v, INF);
    }
    // 無向グラフの構築
    void undirected_update(int x, int y, int cost) {
        G[x].push_back({y, cost});
        G[y].push_back({x, cost});
    }
    // 有向グラフの構築
    void directed_update(int from, int to, int cost) {
        G[from].push_back({to, cost});
    }

    // ダイクストラの計算
    void calc(int start) {
        priority_queue<P, vector<P>, greater<P>> que;
        dist[start] = 0;
        que.push({0, start});

        while (!que.empty()) {
            auto p = que.top();
            que.pop();
            int v = p.second;
            if (dist[v] < p.first)
                continue;
            for (int i = 0; i < G[v].size(); i++) {
                auto e = G[v][i];
                if (dist[v] + e.cost < dist[e.to]) {
                    dist[e.to] = dist[v] + e.cost;
                    que.push({dist[e.to], e.to});
                }
            }
        }
    }

    // calc で渡した start からの最短経路を返す
    // 最短経路が存在しないとき -1 を返す
    long long path(int to) { return dist[to] != INF ? dist[to] : -1; }
};

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

    int N;
    cin >> N;
    auto dj = Dijkstra(N);
    REP(i, N - 1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        dj.undirected_update(a, b, c);
    }
    int Q, K;
    cin >> Q >> K;
    dj.calc(K - 1);
    REP(i, Q) {
        int x, y;
        cin >> x >> y;
        ll ans = dj.path(x - 1) + dj.path(y - 1);
        std::cout << ans << '\n';
    }

    return 0;
}

Measured memory_bytes: 9460
import java.util.*;
public class Main {
	public static void main(String[] args){
       Scanner sc = new Scanner(System.in);   
      // 都市数
	  int N = sc.nextInt();
      // 道路本数
	  int M = sc.nextInt();
      //カウント
      int[] count = new int[N];
      for(int i=0;i<M*2;i++){
        count[sc.nextInt()-1]++;
      }
      for(int i=0;i<N;i++){
        System.out.println(count[i]);
      }
    }
}

Measured memory_bytes: 35796
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();

    PriorityQueue<Double> set =
        new PriorityQueue<>(N, Comparator.<Double>naturalOrder().reversed());
    for (int i = 0; i < N; i++) {
      set.add((double) sc.nextLong());
    }

    for (int i = 0; i < M; i++) {
      double max = set.poll();
      set.add(max / 2);
    }
    System.out.println(set.stream().mapToLong(Double::longValue).sum());
  }
}


Measured memory_bytes: 62952
#include<bits/stdc++.h>
using namespace std;
signed main()
{
  
  string a,b,c;
  int d,e,f;
  cin>>a>>b>>c;
  d=a.size();
  e=b.size();
  if(a[d-1]==b[0] && b[e-1]==c[0]){
    cout<<"YES\n";
  }else{
    cout<<"NO\n";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,cost;
};
int main(){

	ll n;
	cin>>n;
	ll t=1,total=0;
	rep(i,n){
		ll a;
		cin>>a;
		if(a==t)t++;
		else total++;
	}
	if(total==n)cout<<"-1"<<endl;
	else cout<<total<<endl;
	return 0;

}




Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

    int i_testCaseNum;
    int i_completeCaseNum;

    scanf("%d%d", &i_testCaseNum, &i_completeCaseNum);

    if (i_testCaseNum == i_completeCaseNum)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
 

ll A[300100];

int main(){
    int N;
    cin >> N;
    map<ll, ll> mp;
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
        mp[a]++;
    }
    sort(A,A+N, greater<ll>());
    ll ans = 0;
    REP(i,N){
        for(ll n = (1LL << 31); n >= 1; n /= 2){
            if(mp[A[i]] == 0) continue;
            ll diff = n - A[i];
            if(!mp.count(diff)) continue;
            int add = 0;
            if(A[i] == diff){
                add = mp[diff]/2;
            }
            else{
                add = min(mp[diff], mp[A[i]]);
            }
            ans += add;
            mp[diff] -= add;
            mp[A[i]] -= add;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 14336
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
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; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
ll gcd(ll a, ll b);


bool solve(ll f, ll s);

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

	vector<ll> a(n + 1, 0), b(n + 1, 0);
	ll tot = 0;

	rep(i, n) {
		cin >> a[i + 1];
		tot += a[i + 1];
	}
	
	b[1] = tot;

	rep(i, n) {
		if(i % 2 == 0) b[1] -= 2 * a[i];
	}
	
	rep(i, n - 1) {
		b[i + 2] = (2 * a[i + 1] - b[i + 1]);
	}

	rep(i, n) {
		cout << b[i + 1] << " ";
	}

	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0)return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

Measured memory_bytes: 4848
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#define maxn 100010
using namespace std;
typedef long long ll;
ll n,m;
char s[maxn],t[maxn];
map<ll,int>ma;
ll gcd(ll x,ll y)
{
	if(y==0)  return x;
	return gcd(y,x%y);
}
int main()
{
	cin>>n>>m;
	scanf("%s%s",s+1,t+1); 
	ll lcm=n*m/gcd(n,m);
	for(int i=1;i<=n;i++)
	{
		ma[(i-1)*lcm/n+1]=s[i]-'a'+1;
	}
	for(int i=1;i<=m;i++)
	{
		if(ma[(i-1)*lcm/m+1]==0)  continue;
		if(ma[(i-1)*lcm/m+1]!=t[i]-'a'+1)
		{
			puts("-1");
			return 0;
		}
	}
	printf("%lld\n",lcm);
	return 0;
}

Measured memory_bytes: 10880
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<climits>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define	mp	make_pair
#define	pb	push_back
#define	pf	push_front

using namespace std;

typedef	vector<int>			vi;
typedef	vector<vi>			vvi;
typedef	pair<int,int>		pii;
typedef	pair<double,int>	pdi;

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

struct P{
	P(){}
	P(int xx,int yy){x=xx,y=yy;}
	int x,y;
};

struct Piece{
	Piece(){}
	vector<P> blk;
	int xl,xr;
	double m;
};

int w,h,chk[60][10];
char bld[60][11];

Piece makePiece(const vector<P> &blk)
{
	int xl=10,xr=0;
	for(int i=0;i<blk.size();i++){
		int x=blk[i].x,y=blk[i].y;
		if(y==0 || (bld[y-1][x]!='.' && chk[y][x]!=chk[y-1][x])){
			xl=min(xl,x);
			xr=max(xr,x+1);
		}
	}

	Piece pic;
	pic.blk=blk;
	pic.xl=xl;
	pic.xr=xr;
	return pic;
}

void search(P now,char c,int id,vector<P> &blk)
{
	int x=now.x,y=now.y;

	if(bld[y][x]!=c || chk[y][x]!=-1)	return;

	blk.pb(now);
	chk[y][x]=id;

	for(int i=0;i<4;i++){
		int xx=x+dx[i],yy=y+dy[i];
		if(xx<0||w<=xx||yy<0||h<=yy)	continue;
		search(P(xx,yy),c,id,blk);
	}
}

vvi branch;
vector<Piece> piece;
pdi calcCenter(int id)
{
	int num=piece[id].blk.size();
	double xsum=0;
	for(int i=0;i<num;i++)	xsum+=piece[id].blk[i].x+0.5;

	for(int i=0;i<branch[id].size();i++){
		pdi data=calcCenter(branch[id][i]);
		xsum+=data.first;
		num+=data.second;
	}
	piece[id].m=xsum/num;
	return mp(xsum,num);
}

int main()
{
	for(;cin>>w>>h,w;){
		for(int y=h-1;y>=0;y--)	cin>>bld[y];

		for(int y=0;y<h;y++)for(int x=0;x<w;x++)chk[y][x]=-1;

		piece.clear();
		int id=0;
		for(int y=0;y<h;y++)for(int x=0;x<w;x++){
			if(bld[y][x]!='.' && chk[y][x]==-1){
				vector<P> block;
				search(P(x,y),bld[y][x],id++,block);
				piece.pb(makePiece(block));	// the root piece is always piece[0]
			}
		}

		branch=vvi(piece.size());	// adjacent list
		for(int i=0;i<branch.size();i++){
			for(int j=0;j<piece[i].blk.size();j++){
				P p=piece[i].blk[j];
				if(p.y<h-1 && chk[p.y+1][p.x]!=-1 && chk[p.y+1][p.x]!=i){
					branch[i].pb(chk[p.y+1][p.x]);
				}
			}
			sort(branch[i].begin(),branch[i].end());
			branch[i].erase(unique(branch[i].begin(),branch[i].end()),branch[i].end());
		}

		calcCenter(0);

		bool ok=true;
		for(int i=0;i<piece.size();i++){
			if(!(piece[i].xl<piece[i].m && piece[i].m<piece[i].xr))	ok=false;
		}
		if(ok)	cout<<"STABLE"<<endl;
		else	cout<<"UNSTABLE"<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int a[300005];
int st[3000005];

/// 1 5 4 3 8 6 9 7 2 4
///


void update(int n, int s, int e, int i, int val){
    if(s == e) st[n] = max(st[n], val);//cout<<n<<" "<<st[n]<<endl;
    else{
        int mid = (s+e)/2;
        if(i <= mid) update(n+n, s, mid, i, val);
        else update(n+n+1, mid+1, e, i, val);

        st[n] = max(st[2*n], st[2*n+1]);
        //cout<<n<<" "<<st[n]<<endl;
    }
}
int query(int n, int s, int e, int l, int r){
    if(s > r || l > e) return 0;
    if(l <= s && e <= r) return st[n];
    int mid = (s+e)/2;
    int d= max(query(n+n, s, mid, l, r), query(n+n+1, mid+1, e, l, r));
    //cout<<n<<" "<<s<<" "<<e<<" "<<d<<endl;
    return d;
}
int dp[300005];

int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    int ans = 0;
    for(int i=1;i<=n;i++){
        scanf("%d", &a[i]);
        dp[i] = query(1, 0, 300000, max(0, a[i]-k), min(300000, a[i]+k)) + 1;

        update(1, 0, 300000, a[i], dp[i]);
        //cout<<st[0]<<endl;
        ans = max(ans, dp[i]);
    }


        printf("%d\n", ans);
}


Measured memory_bytes: 10232
#include <cstdio>
using namespace std;

#define MAX 500000

struct Node
{
	int key;
	Node *parent, *left, *right;
public:
	Node() { parent = left = right = NULL; }
};

Node *root;

void insert(int u)
{
	Node *y = NULL;
	Node *x = root;
	Node *z = new Node();
	z->key = u;
	//?????????????????§?§????
	while (x != NULL) {
		y = x;
		if (z->key < x->key)
			x = x->left;
		else x = x->right;
	}
	z->parent = y;

	//?????????????????????????????\
	if (y == NULL) root = z;
	else if (z->key < y->key) y->left = z;
	else y->right = z;
}

Node *find(Node *n, int u)
{
	while (n != NULL && n->key != u) {
		if (u < n->key) n = n->left;
		else n = n->right;
	}
	return n;
}

void Preorder(Node *n)
{
	if (n == NULL) return;
	printf(" %d", n->key);
	Preorder(n->left);
	Preorder(n->right);
}

void Inorder(Node *u)
{
	if (u == NULL) return;
	Inorder(u->left);
	printf(" %d", u->key);
	Inorder(u->right);
}

int main()
{
	int n;
	scanf("%d", &n);

	char order[20];
	int z;
	for (int i = 0; i < n; i++) {
		scanf("%s", order);
		switch (order[0])
		{
		case 'i':
			scanf("%d", &z);
			insert(z);
			break;
		case 'p':
			Inorder(root);
			printf("\n");
			Preorder(root);
			printf("\n");
			break;
		case 'f':
			scanf("%d", &z);
			if (find(root, z) != NULL) printf("yes\n");
			else printf("no\n");
			break;
		default:
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 19792
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>

using namespace std;

int main()
{
	while (1)
	{
		int a = 0;
		int b = 0;
		cin >> a;
		cin >> b;
		if (a == 0)break;
		if (a == 2)b += 31;
		if (a == 3)b += 31 + 29;
		if (a == 4)b += 60 + 31;
		if (a == 5)b += 91 + 30;
		if (a == 6)b += 121 + 31;
		if (a == 7)b += 152 + 30;
		if (a == 8)b += 182 + 31;
		if (a == 9)b += 213 + 31;
		if (a == 10)b += 30 + 244;
		if (a == 11)b += 31 + 274;
		if (a == 12)b += 30 + 305;
		if (b % 7 == 1)cout << "Thursday" << endl;
		if (b % 7 == 2)cout << "Friday" << endl;
		if (b % 7 == 3)cout << "Saturday" << endl;
		if (b % 7 == 4)cout << "Sunday" << endl;
		if (b % 7 == 5)cout << "Monday" << endl;
		if (b % 7 == 6)cout << "Tuesday" << endl;
		if (b % 7 == 0)cout << "Wednesday" << endl;
	}
	return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str;
            List<int> digit = new List<int>();

            while (!((str = Console.ReadLine()) == null))
            {
                int sum = 0;
                List<int> num = str.Split(' ').Select(int.Parse).ToList();

                sum = num.Sum();
                digit.Add(sum.ToString().Length);
            }

            foreach (int item in digit)
            {
                Console.WriteLine(item);
            }
        }
    }
}



Measured memory_bytes: 16376
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
using ll = long long;
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() {
  string s, t;
  cin >> s >> t;
  int m=s.length();
  int n=t.length();
  //int count=0;
  int min=1001;
  rep(i,m-n+1){
    int count=0;
    rep(j,n){
      if(s[i+j]!=t[j]) count++;
    }
    chmin(min,count);
  }
  //if(min>count) min=count;
  //chmin(min,count);
  cout << min << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	int ans = upper;
	rep(i, n) {
		int x;
		cin >> x;
		int tmp = 0;
		while (x % 2 == 0) { x /= 2; tmp++; }
		chmin(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
	int n,flag=0;
	cin>>n;
	while(n != 0)
	{
		if(n%10 != 7)
		{
			n /= 10;
		}
		else
		{
			flag = 1;
			cout<<"Yes";
			break;
		}
	}
	if(flag == 0)
	{
		cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 3624
N=int(input())
S=input()
a=[]
b=[]
for i in range(26):
  a.append(chr(i+65))

for j in range(len(S)):
  for k in range(26):
    if S[j]==a[k]:
      b.append(a[(k+N)%26])
      break;
o=''.join(b)
print(o)

Measured memory_bytes: 3060
#include<cstdio>
static const int MAX = 100002;

int calcost(int a, int b)
{
    int cost = (a >= b) ? (a - b) : (b - a);
    return cost;
}

int main()
{
    int N;
    int A[MAX];
    scanf("%d", &N);
    A[0] = 0;
    for (int i = 1; i <= N; i++)
    {
        scanf("%d", &A[i]);
    }
    A[N + 1] = 0;
    int S = 0;
    for (int i = 0; i <= N; i++)
    {
        int cost = calcost(A[i + 1], A[i]);
        S += cost;
    }
    for (int i = 1; i <= N; i++)
    {
        int x = calcost(A[i], A[i - 1]);
        int y = calcost(A[i + 1], A[i]);
        int z = calcost(A[i + 1], A[i - 1]);
        int result = S - x - y + z;
        printf("%d\n", result);
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    vector<vector<int>> dp(n, vector<int>(3, 1));
    int ans = 0;
    for(int i = 1; i < n; i++){
        dp[i][0] = a[i]!=a[i-1] ? dp[i-1][0]+1 : 1;
        dp[i][1] = a[i]!=a[i-1] ? dp[i-1][1]+1 : dp[i-1][0]+1;
        dp[i][2] = a[i]!=a[i-1] ? dp[i-1][2]+1 : dp[i-1][1]+1;
        ans = max({ans, dp[i][0], dp[i][1], dp[i][2]});
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8684
import Control.Applicative
import qualified Control.Monad as Monad (when)

main = loopGrading

loopGrading :: IO ()
loopGrading = do
    result <- map (read :: String -> Int) . words <$> getLine
    Monad.when (any (/= (-1)) result) $ do
        putStrLn $ grading result
        loopGrading

grading :: [Int] -> String
grading [m,f,r]
    | m == (-1) || f == (-1) = "F"
    | total >= 80            = "A"
    | total >= 65            = "B"
    | total >= 50 || r >= 50 = "C"
    | total >= 30            = "D"
    | otherwise              = "F"
    where total = m + f

Measured memory_bytes: 4096
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
h=[int(i) for i in input().split()]
ans=0
while 1:
    l=0
    for i in range(n):
        if h[i]>0:
            l=i
            break
    else:
        print(ans)
        exit()
    
    while h[l]!=0:
        #print(l)
        h[l]-=1
        if l!=n-1:
            l+=1
        else:
            break
        
    ans+=1

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    double a, b, c, d, e, f;
    while(true) {
        cin >> a;
        if(cin.eof()) break;
        cin >> b >> c >> d >> e >> f;
        double det = a * e - b * d;
        if(det == 0.0) break;
        cout << fixed << setprecision(3);
        cout << ((e*c/det-b*f/det)) << " " << ((-d*c/det+a*f/det)) << endl;
    }

    return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

int a[200];
int check(long long a,long long b,long long c){
    if (a+b>c && a+c>b && b+c>a)
        return 1;
    return 0;
}
int main()
{
    int n;scanf("%d",&n);
    for (int i=0;i<n;++i)
        scanf("%d",&a[i]);
    int ans=0;
    for (int i=0;i<n;++i)
        for (int j=i+1;j<n;++j)
            for (int k=j+1;k<n;++k){
                if (a[i]==a[j]) continue;
                if (a[i]==a[k]) continue;
                if (a[j]==a[k]) continue;
                if (check(a[i],a[j],a[k]))
                    ans++;
            }
    printf("%d\n",ans);
    return 0;
}

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

int main()
{
	int n;
	cin>>n;
	if(n<=9)
	{
		if(n==2||n==4||n==5||n==7||n==9)
		{
			cout<<"hon"<<endl;
		}
	else	if(n==0||n==1||n==6||n==8)
		{
			cout<<"pon";
		}
		else if(n==3)
		cout<<"bon";
	}
	if(n>=10&&n<100)
	{
		int s = n%10;
		if(s==2||s==4||s==5||s==7||s==9)
		{
			cout<<"hon";
		}
	else	if(s==0||s==1||s==6||s==8)
		{
			cout<<"pon";
		}
		else if(s==3)
		cout<<"bon";
	}
	if(n>=100&&n<=999)
	{
		int s = n%100,g = s%10;
			if(g==2||g==4||g==5||g==7||g==9)
		{
			cout<<"hon";
		}
	else	if(g==0||g==1||g==6||g==8)
		{
			cout<<"pon";
		}
		else if(g==3)
		cout<<"bon";
	}
	return 0;
 }

Measured memory_bytes: 3568
#include <string>
#include <cstdio>
#include <vector>
#include <iostream>
using namespace std;

const int N = 200010;
struct Node {
	vector<int> son;
	int fa;
	int lazy;
} v[N];
int val[N];

void dfs(int x = 1) {
	val[x] += v[x].lazy;
	for (int i = 0; i < v[x].son.size(); ++i)
		v[v[x].son[i]].lazy += v[x].lazy,
		dfs(v[x].son[i]);
}

int main() {
	int n, q; scanf("%d%d", &n, &q);
	for (int i = 1; i < n; ++i) {
		int x, y; scanf("%d%d", &x, &y);
		v[x].son.push_back(y);
	}
	while (q--) {
		int x, y; scanf("%d%d", &x, &y);
		v[x].lazy += y;
	}
	dfs();
	for (int i = 1; i <= n; ++i)
		printf("%d ", val[i]);
	return 0;
}

Measured memory_bytes: 21888
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		string o = Console.ReadLine();
		string e = Console.ReadLine();
		var ans = new StringBuilder();

        for(int i = 0; i < o.Length + e.Length; i++)
		{
			if (i % 2 == 0)
			{
				ans.Append(o[i / 2]);
			}
			else
			{
				ans.Append(e[(i - 1) / 2]);
			}
		}
		Console.WriteLine(ans);
	}
}

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

void black(vector<string>& board, int h, int w, int i, int j){
    char N='o', E='o', S='o', W='o';
    if ((i>0) && (h>2)){
        N = board[i-1][j];
        if (N == '#') {
            board.at(i)[j] = 'o';
            board.at(i-1)[j] = 'o';
            black(board, h, w, i-1, j);
        }
    }
    if ((i < h-1) && (h>2)){
        S = board[i+1][j];
        if (S == '#') {
            board.at(i)[j] = 'o';
            board.at(i+1)[j] = 'o';
            black(board, h, w, i+1, j);
        }
    }
    if ((j>0) && (w>2)){
        W = board[i][j-1];
        if (W == '#') {
            board.at(i)[j] = 'o';
            board.at(i)[j-1] = 'o';
            black(board, h, w, i, j-1);
        }
    }
    if ((j < w-1) && (w>2)){
        E = board[i][j+1];
        if (E == '#') {
            board.at(i)[j] = 'o';
            board.at(i)[j+1] = 'o';
            black(board, h, w, i, j+1);
        }
    }

}

int main(int argc, char const* argv[])
{
    int h, w;
    cin >> h >> w;

    vector<string> board(h);
    for (int i = 0; i < h; i++) {
        cin >> board[i];
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (board[i][j] == '#') {
                black(board, h, w, i, j);
            }
        }
    }

    int c=0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (board[i][j] == '#') {
                c++;
            }
            // cout << board[i][j];
        }
        // cout << endl;
    }

    if (c==0) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
N=int(input())
q=1
t=[0]*N
for i in range(2,N+1):
    s=1
    while i>1:
        s+=1
        while i%s==0:
            i=i//s
            t[s-2]+=1
for j in range(N):
    q=q*(t[j]+1)%(10**9+7)
print(q)

Measured memory_bytes: 3060
import itertools

N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]

def min_cost(target, l_list):
  if target in l_list:
    return 0
  else:
    res = 1000
    for l in l_list:
      res = min(res, abs(target - l))
    
    for i, l in enumerate(l_list):
      res = min(res, min_cost(target-l, l_list[:i]+l_list[i+1:]) + 10)
  
    return res

ans = 1000 * 3
combs = list(itertools.product([0, 1, 2], repeat=N))
for comb in combs:
  labc = [[], [], []]
  for i, idx in enumerate(comb):
    labc[idx].append(L[i])
  
  la, lb, lc = labc
  if len(la)*len(lb)*len(lc):
    ans = min(ans, min_cost(A, la)+min_cost(B, lb)+min_cost(C, lc))

print(ans)

Measured memory_bytes: 3828
fun main(args:Array<String>){
    val l = readLine()!!.split(" ").map {it.toInt()}
    val n = l[0]
    val m = l[1]
    val q = l[2]
    val a = Array(q){0}
    val b = Array(q){0}
    val c = Array(q){0}
    val d = Array(q){0}
    (0..q-1).map {
        val ll = readLine()!!.split(" ").map {it.toInt()}
        a[it] = ll[0]-1
        b[it] = ll[1]-1
        c[it] = ll[2]
        d[it] = ll[3]
    }
    var result = 0L
    fun dfs(arg:Pair<Int,Int>,array:Array<Int>){
        val current = arg.first
        val max = arg.second
        //実装部分
        var sum = 0L
        (0..q-1).map{
            if(array[b[it]]-array[a[it]]==c[it]){
                sum += d[it]
            }
        }
        if(sum>result)result=sum
        if(current>0){
            val copy = array.copyOf()
            copy[current-1]++
            if(copy[current-1]<=copy[current]) {
                dfs(Pair(current - 1, copy[current]), copy)
            }
        }
        if(array[current]<max){
            val copy = array.copyOf()
            copy[current]++
            dfs(Pair(current,max),copy)
        }
    }
    dfs(Pair(n-1,m),Array(n){1})
    println(result)
}

Measured memory_bytes: 56248
l=map(int,raw_input().split())
n=raw_input()
ans=chk=0
 
 
def rolling(word,dice):
    if word=='S':
        dice[0],dice[1],dice[5],dice[4]=dice[4],dice[0],dice[1],dice[5]
    elif word=='N':
        dice[0],dice[1],dice[5],dice[4]=dice[1],dice[5],dice[4],dice[0]
    elif word=='W':
        dice[0],dice[2],dice[5],dice[3]=dice[2],dice[5],dice[3],dice[0]
    else:
        dice[0],dice[2],dice[5],dice[3]=dice[3],dice[0],dice[2],dice[5]
    return dice
 
for i in n:
    l=rolling(i,l)
print l[0]


Measured memory_bytes: 4684
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  int n;
  cin>>n;
  int mx=0;
  vector<int> v;
  bool f=true;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    v.push_back(a);
    if(mx<i) f=false;
    mx=max(a/10+i,mx);
  }
  int mn=0;
  for(int i=n-1;i>=0;i--){
    int pos=(n-1)-i;
    if(mn<pos) f=false;
    mn=max(v[i]/10+pos,mn);
  }
  cout<<(f?"yes":"no")<<endl;
}



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

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

int N,M;
int A[400],B[400];
vector<int> E[20];
vector<int> path[20][20];
int rev[20][20];
int ne[1<<20];
ll C[1<<20],S[1<<20];
ll mo=1000000007;


const int NUM_=400001;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

ll comb(ll N_, ll C_) {
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

void solve() {
	int i,j,k,l,r,x,y; string s;

	inv[1]=fact[0]=factr[0]=1;
	for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
	for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	
	MINUS(rev);
	cin>>N>>M;
	FOR(i,M) {
		cin>>A[i]>>B[i];
		A[i]--;
		B[i]--;
		if(i<N-1) {
			E[A[i]].push_back(B[i]);
			E[B[i]].push_back(A[i]);
		}
		rev[A[i]][B[i]]=rev[B[i]][A[i]]=i;
	}
	
	FOR(i,N) {
		path[i][i].push_back(i);
		queue<int> Q;
		Q.push(i);
		while(Q.size()) {
			x=Q.front();
			Q.pop();
			FORR(e,E[x]) if(path[i][e].empty()) {
				path[i][e]=path[i][x];
				path[i][e].push_back(e);
				Q.push(e);
			}
		}
	}
	FOR(i,M) {
		int mask=0;
		FOR(j,path[A[i]][B[i]].size()-1) mask |= 1<<(rev[path[A[i]][B[i]][j]][path[A[i]][B[i]][j+1]]);
		ne[mask]++;
	}
	FOR(i,N-1) FOR(j,1<<(N-1)) if(j&(1<<i)) ne[j]+=ne[j^(1<<i)];
	C[(1<<(N-1))-1]=1;
	
	int mask;
	for(int mask=(1<<(N-1))-1;mask>0;mask--) {
		int num=(N-1)-__builtin_popcount(mask);
		FOR(j,N-1) if((mask&(1<<j))) {
			int CN=M-ne[mask];
			int W=ne[mask]-ne[mask^(1<<j)]-1;
			ll wc=C[mask]*fact[CN+W]%mo*factr[CN]%mo;
			ll ws=S[mask]*fact[CN+W+1]%mo*factr[CN+1]%mo;
			(C[mask^(1<<j)]+=wc)%=mo;
			(S[mask^(1<<j)]+=ws+(num+1)*wc)%=mo;
		}
	}
	
	cout<<S[0]<<endl;
	
	
}


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


Measured memory_bytes: 26112
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int N;
    ll W;
    cin >> N >> W;
    vector<vector<ll>> vec(4);
    ll wmin;
    REP(i, N){
        ll w, v;
        cin >> w >> v;
        if(i == 0){
            vec[0].push_back(v);
            wmin = w;
        }else{
            vec[w - wmin].push_back(v);
        }
    }
    
    REP(i, 4){
        sort(all(vec[i]), [](auto a, auto b){return a > b;});
    }

    ll ans = 0;
    vector<vector<ll>> sum(4);
    for(int i=0; i<4; i++){
        sum[i].push_back(0LL);
        for(int j=0; j<vec[i].size(); j++){
            sum[i].push_back(vec[i][j] + sum[i].back());
        }
    }

    REP(i, sum[0].size()){
        REP(j, sum[1].size()){
            REP(k, sum[2].size()){
                ll w, v;
                v = sum[0][i] + sum[1][j] + sum[2][k];
                w = wmin*i + (wmin+1)*j + (wmin+2)*k;

                if(W - w >= 0){
                    v += sum[3][min((ll)(sum[3].size()-1), (W - w)/(wmin+3))];
                    ans = max(ans, v);
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n;
    cin >>n;
    vi s(n, 0);
    rep(i,n-1) {
        int x;
        cin >> x;
        x--;
        s[x]++;
    }
    rep(i,n) {
        cout << s[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4048
from fractions import gcd
n, m, *a = map(int, open(0).read().split())
lcm = a[0] // 2
for x in a:
	x //= 2
	g = gcd(lcm, x)
	if (lcm // g) % 2 != (x // g) % 2:
		print(0)
		exit()
	lcm = lcm * x // g
print(m // (2 * lcm) + (m % (2 * lcm) >= lcm))

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

unsigned long minimum(unsigned long a, unsigned long b) {
  if(a > b) return b;
  else return a;
}

int main() {
  unsigned long N, K;
  cin >> N >> K;

  unsigned long candidate1 = N % K;
  unsigned long candidate2 = K - candidate1;

  cout << minimum(candidate1, candidate2) << endl;
  return 0;
}


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

ll N, K, Q;
vector<ll> A(1e5+5);

int main(){

    cin >> N >> K >> Q;

    for (int i=0; i<Q; i++){
        ll tmp;
        cin >> tmp;
        A.at(tmp)++;
    }

    ll sum = 0;
    for (int i=1; i<=N; i++){
        sum += A.at(i);
    }

    ll thr;
    for (int i=1 ;i<=N; i++){
        thr = K - (sum - A.at(i));
        if (thr > 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    return 0;
}

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

int main() {
  int n,m;
  cin>>n>>m;
  vector<int>s(m);
  vector<char>c(m);
  for(int i=0;i<m;i++) cin>>s[i]>>c[i];
  long long ans=-1;
  int b=pow(10,n);
  if(n==1){
  for(int i=pow(10,n-1)-1;i<b;i++){
    string answer=to_string(i);
    int j=0;
    while(j<m){
      if(answer[s[j]-1]!=c[j]) break;
      j++;
    }
    if(m==0 || j==m) {
      ans=i;
      break;
    }
  }
  cout<<ans<<endl;
  }
  if(n!=1){
  for(int i=pow(10,n-1);i<b;i++){
    string answer=to_string(i);
    int j=0;
    while(j<m){
      if(answer[s[j]-1]!=c[j]) break;
      j++;
    }
    if(m==0 || j==m){
      ans=i;
      break;
    }
  }
  cout<<ans<<endl;
  }
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


int main(){
  int n,d;
  cin>>n>>d;
  int sum=0;
  int x=0;
  while(x<n){
    x+=2*d+1;
    sum++;
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.size(),sum=0,land[25000]={},area = 0;
    stack<int> dis;
    vector<int> ans;
    for(int i=0;i<n;i++){
        if(s[i]=='\\') dis.push(i);
        else if(s[i]=='/'){
            if(!dis.empty()){
                land[i]++;
                land[dis.top()]++;
                for(int j=dis.top()+1;j<i;j++) land[j]+=2;
                dis.pop();
            }
        }
    }
    for(int i=0;i<n;i++){
        area += land[i];
        if(land[i]==1&&s[i]=='/'){
            ans.push_back(area/2);
            sum += area/2;
            area = 0;
        }
    }
    int b = ans.size();
    cout << sum << endl;
    if(b==0){
        cout << 0 << endl;
        return 0;
    } 
    cout << b <<' ';
    for(int i=0;i<b-1;i++) cout << ans[i] << ' '; 
    cout << ans[b-1] << endl;
}


Measured memory_bytes: 3360
#include <bits/stdc++.h>
using namespace std;
 
int fun(int a){
  return (a%2==0 ? a/2:a*3+1);
}

int main() {
  int s;cin>>s;
  int i=1;
  while(true){
    if(s==4||s==2||s==1)break;
    s=fun(s);
    i++;
  }
  cout<<i+3<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

const int N = 100003;

ll ans = 0;

namespace SegmentTree {
	ll mx[N << 2];
	ll d[N << 2], a0[N << 2];
	
	void add(int rt, int l, int r, int L, int R, int sx) {
		if (L <= l && r <= R) {a0[rt] += sx + (l - L); ++d[rt]; return;}
		int mid = (l + r) >> 1;
		if (L <= mid) add(rt << 1, l, mid, L, R, sx);
		if (R > mid) add(rt << 1 | 1, mid + 1, r, L, R, sx);
	}
	
	void pushdown(int rt, int l, int r) {
		if (l == r) {mx[rt] = a0[rt]; return;}
		int mid = (l + r) >> 1;
		a0[rt << 1] += a0[rt]; d[rt << 1] += d[rt];
		a0[rt << 1 | 1] += a0[rt] + d[rt] * (mid - l + 1); d[rt << 1 | 1] += d[rt];
		pushdown(rt << 1, l, mid);
		pushdown(rt << 1 | 1, mid + 1, r);
		mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]);
	}
}

int n, m, a[N];

int main() {
//	freopen("C.in", "r", stdin);
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) scanf("%d", a + i);
	
	for (int i = 2; i <= n; ++i) {
		if (a[i] > a[i - 1]) {
			ans += a[i] - a[i - 1];
			SegmentTree::add(1, 1, m, a[i - 1] + 1, a[i], 0);
		} else {
			ans += m - a[i - 1] + a[i];
			SegmentTree::add(1, 1, m, a[i - 1] + 1, m, 0);
			SegmentTree::add(1, 1, m, 1, a[i], m - a[i - 1]);
		}
	}
	
	SegmentTree::pushdown(1, 1, m);
	printf("%lld\n", ans - SegmentTree::mx[1]);
	return 0;
}

Measured memory_bytes: 8832
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF 1<<30
#define LINF 1LL<<60

class Bellman_ford {
public:
	struct edge {
		ll u;
		ll v;
		ll cost;
		edge() {}
		edge(ll u, ll v, ll c) :u(u), v(v), cost(c) {}
	};

	ll V;
	vector<vector<edge>> G;
	vector<ll> dist;
	Bellman_ford(ll V) :V(V) {
		G.resize(V);
	}

	void add_edge(ll u, ll v, ll cost, bool undirected = false) {
		G[u].push_back(edge(u, v, cost));
		if (undirected) {
			G[v].push_back(edge(v, u, cost));
		}
	}

	bool calc_dist(ll s) {
		dist.assign(V, INF);
		dist[s] = 0;

		for (int i = 0; i < V;i++) {
			for (int v = 0; v < V;v++) {
				for (auto e : G[v]) {
					if (dist[v] != INF && dist[e.v] > dist[v] + e.cost) {
						dist[e.v] = dist[v] + e.cost;
						if (i == V - 1) return true; // ????????????
					}
				}
			}
		}
		return false;
	}

	inline ll get_dist(ll v) const { return dist[v]; }
};

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll V, E, r; cin >> V >> E >> r;
	Bellman_ford Bf(V);
	for (int i = 0; i < E;i++) {
		ll s, t, d; cin >> s >> t >> d;
		Bf.add_edge(s, t, d);
	}
	if (Bf.calc_dist(r)) {
		cout << "NEGATIVE CYCLE" << endl;
	}
	else {
		for (int i = 0; i < V;i++) {
			if (Bf.get_dist(i) == INF) {
				cout << "INF" << endl;
			}
			else {
				cout << Bf.get_dist(i) << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3212
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author G. Guarnieri
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();

            while (s.length() > 1) {
                do {
                    s = s.substring(0, s.length() - 1);
                } while (s.length() % 2 == 1);

                if (isEven(s)) {
                    out.println(s.length());
                    break;
                }
            }
        }

        private boolean isEven(String s) {
            int mid = s.length() / 2;
            return s.substring(0, mid).equals(s.substring(mid, s.length()));
        }

    }
}



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

typedef struct{
  double x;
  double y;
}point;


void koch (int d, point left, point right) {
  point s, t, u;

  if (d == 0) {
    printf("%lf %lf\n",left.x,left.y);
    return;
  }

  s.x = (2 * left.x + right.x) / 3;
  s.y = (2 * left.y + right.y) / 3;
  koch(d-1, left, s);

  t.x = (left.x + 2 * right.x) / 3;
  t.y = (left.y + 2 * right.y) / 3;

  u.x = ((t.x - s.x) - sqrt(3) * (t.y - s.y)) / 2 + s.x;
  u.y = ((t.y - s.y) + sqrt(3) * (t.x - s.x)) / 2 + s.y;

  koch(d-1, s, u);
  koch(d-1, u, t);
  koch(d-1, t, right);

  return;
}


int main() {
  int n;
  point start;
  point end;

  start.x = 0;
  start.y = 0;

  end.x = 100;
  end.y = 0;

  scanf("%d", &n);

  koch(n, start, end);

  printf("%lf %lf\n", end.x, end.y);

  return 0;
}



Measured memory_bytes: 2040
import java.util.*;

class Main{
    int H, N;
    int[] A, B, DP;

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

    public Main(){
        Scanner scanner = new Scanner(System.in);
        H = Integer.parseInt(scanner.next());
        N = Integer.parseInt(scanner.next());

        A = new int[N];
        B = new int[N];

        int maxA=0;
        for(int i=0;i<N;i++){
            A[i] = Integer.parseInt(scanner.next());
            B[i] = Integer.parseInt(scanner.next());

            if(A[i] > maxA) maxA = A[i];
        }

        int[] DP = new int[H+maxA];
        DP[0] = 0;
        for(int i=1;i<H+maxA;i++){
            DP[i] = Integer.MAX_VALUE;
            for(int j=0;j<N;j++){
                if(i-A[j]<0){
                    DP[i] = Math.min(DP[i], B[j]);
                } else {
                    DP[i] = Math.min(DP[i], DP[i-A[j]] + B[j]);
                }
            }
        }

        int minDP = DP[H];
        for(int i=1;i<maxA;i++){
            if(minDP > DP[H+i])minDP = DP[H+i];
        }

        System.out.println(minDP);
    }
}


Measured memory_bytes: 27828
from sys import exit
A,B,C = [int(n) for n in input().split()]
# N = int(input())
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
# exit()
print("Yes" if A == B and B == C else "No")


Measured memory_bytes: 2940
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

bool in(int l, int r, const vector<int> &a, const vector<int> &b) {
	int i = l;
	for(const auto &e : a) {
		if(e == b[i]) {
			++i;
			if(i == r) break;
		}
	}
	return i == r;
}

bool ok(int len, const vector<int> &a, const vector<int> &b) {
	for(unsigned l = 0; l + len <= b.size(); ++l) {
		if(in(l, l + len, a, b)) return true;
	}
	return false;
}

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

	vector<int> a(n), b(m);
	for(auto &e : a) cin >> e;
	for(auto &e : b) cin >> e;

	int low = 0, high = min(n, m) + 1;
	while(low + 1 < high) {
		const int mid = (low + high) / 2;
		if(ok(mid, a, b)) {
			low = mid;
		}
		else {
			high = mid;
		}
	}

	cout << low << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1232
#include <stdio.h>
int gcd(int p,int q){
  if(p%q==0)
    return q;
  return gcd(q,p%q);
}
 
int main(void){
  int k;
  scanf("%d",&k);
  int a,b,c;
  int n;
  int sum=0;
  
  for(a=1;a<=k;a++){
    for(b=1;b<=k;b++){
      for(c=1;c<=k;c++){
        n=gcd(gcd(a,b),c);
        sum=sum+n;
      }
    }
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 1724
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll cnt(n) ;
	for(auto &i:cnt) cin >> i ;
	cnt.push_back(0) ;
	ll ans = 0 ;
	for(int i=0;i<n;i++){
		ans += cnt.at(i)/2 ;
		if(cnt.at(i)&1){
			if(cnt.at(i+1)!=0){
				ans++ ;
				cnt.at(i+1)-- ;
			}
		}
	}
	cout << ans << endl ;
}


Measured memory_bytes: 1920
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    int N;
    cin >> N;

    vector<ll> X(N), Y(N);
    rep(i, 0, N) cin >> X[i] >> Y[i];

    ll max_xy = 0;
    for (int i = 0; i < N - 1; ++i) {
        if (abs(X[i] + Y[i]) % 2 != abs(X[i + 1] + Y[i + 1]) % 2) {
            cout << -1 << endl;
            return 0;
        }
        chmax(max_xy, abs(X[i]) + abs(Y[i]));
    }
    chmax(max_xy, abs(X[N - 1]) + abs(Y[N - 1]));

    vector<ll> v;
    if (abs(X[0] + Y[0]) % 2 == 0) {
        v.push_back(1ll);
    }
    v.push_back(1ll);
    for (int i = 0; v.back() + 1 < max_xy; ++i) {
        v.push_back(v.back() * 2ll);
    }

    reverse(all(v));

    int m = v.size();
    cout << m << endl;
    for (int i = 0; i < m; ++i) {
        cout << v[i];
        if (i < m - 1) cout << " ";
        else cout << endl;
    }
    for (int i = 0; i < N; ++i) {
        ll x = X[i];
        ll y = Y[i];

        string ans;
        for (int j = 0; j < m; ++j) {
            if (abs(x) > abs(y)) {
                if (x > 0) {
                    x -= v[j];
                    ans += 'R';
                } else {
                    x += v[j];
                    ans += 'L';
                }
            } else {
                if (y > 0) {
                    y -= v[j];
                    ans += 'U';
                } else {
                    y += v[j];
                    ans += 'D';
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
int main() {
    int X;
    string ans;
    cin >> X;
    if(X==7||X==5||X==3) {
        ans = "YES";
    }else{
        ans="NO";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256