akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
   ll N,L;
   cin >> N >> L;
   bool flag = 0;
   vector<ll> A(N),ans;
   rep(i,N){
      cin >> A[i];
      if(i != 0){
         if(A[i] + A[i-1] >= L && !flag){
            FOR(j,1,i) ans.push_back(j);
            RFOR(j,i+1,N) ans.push_back(j);
            ans.push_back(i);
            flag = 1;
         }
      }
   }
   if(flag){
      cout << "Possible" << endl;
      rep(i,N-1) cout << ans[i] << endl;
   }else{
      cout << "Impossible" << endl;
   }
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
long long n,a=0,b=0,c=0,ans=0;
string s;
int main(){
  cin >> s;
  for(int i=0;i<3;i++){
    if(s[i]=='a'){
      a++;
    }else if(s[i]=='b'){
      b++;
    }else if(s[i]=='c'){
      c++;
    }
  }
  if(a==1&&b==1&&c==1){    
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
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; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)



int main(){
    int n;
    cin>>n;
    int64_t a[n];
    int count2=0;
    int count4=0;
    rep(i,n){
        cin>>a[i];
        if(a[i]%4==0) count4++;
        else if(a[i]%2==0) count2++;
    }

    bool ans=false;
    n-=2*count4;
    if(n%2==1) n--;
    if(n<=0) ans=true;
    else if(n<=count2) ans=true;

    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 4392
#include <iostream>

using namespace std;

int main(void) {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(A+B < C+D) {
        cout << "Right" << endl;
    } else if(A+B == C+D) {
        cout << "Balanced" << endl;
    } else {
        cout << "Left" << endl;
    }
    return 0;
}


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

using namespace std;

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

  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p[i];
  }

  int ans = 0, min = p[0];
  for(int i = 0; i < n; i++){
    if(p[i] <= min){
      ans++;
      min = p[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	s := sc.Text()

	for _, r := range s {
		rr := r
		if 'A' <= r && r <= 'Z' {
			rr = r + 32
		} else if 'a' <= r && r <= 'z' {
			rr = r - 32
		}
		fmt.Printf("%c", rr)
	}
	fmt.Println()
}



Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
string R(string s,string t,string u){
int p=s.find(t);
while(p!=string::npos){
s.replace(p,t.size(),u);
p=s.find(t,p+u.size());
}
return s;
}
string B[14]={"-T","-F","(T*T)","(T*F)","(F*T)","(F*F)","(T+T)","(T+F)","(F+T)","(F+F)","(T->T)","(T->F)","(F->T)","(F->F)"},A[14]={"F","T","T","F","F","F","T","T","T","F","T","F","T","T"};
string k(string s){
while(s!="T" && s!="F")for(int i=0;i<14;i++)s=R(s,B[i],A[i]);
return s;
}
int main(){
for(string S,s;cin>>S,S!="#";){
int f=1;
map<string,int>M;
for(int b=0;b<2048;b++){
s=S;
for(int i=1,c='a';c<'l';i*=2,c++)replace(s.begin(),s.end(),(char)c,(b&i?'T':'F'));
if(M[s]==1)continue;
else M[s]=1;
if(k(s.substr(0,s.find("=")))!=k(s.substr(s.find("=")+1)))f=0;
}
cout<<(f?"YES":"NO")<<endl;
}
}


Measured memory_bytes: 1716
#include<bits/stdc++.h>
using namespace std;
const int N=3010;
int head[N],cnt,n;
struct edge
{
	int to,next;
}e[N<<1];
void adde(int a,int b)
{
	e[++cnt].to=b; e[cnt].next=head[a]; head[a]=cnt;
}
int a[N],ans[N];
void dfs(int k)
{
	ans[k]=0;
	for(int i=head[k];i;i=e[i].next)
	{
		int v=e[i].to;
		if(a[k]>a[v])
		{
			if(ans[v]==-1)
				dfs(v);
			if(ans[v]==0){ans[k]=1;return;}
		}
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	memset(ans,-1,sizeof(ans));
	int u,v;
	for(int i=1;i<n;i++)
		scanf("%d%d",&u,&v),adde(u,v),adde(v,u);
	for(int i=1;i<=n;i++)
	{
		if(ans[i]==-1)dfs(i);
		if(ans[i]==1)
			printf("%d ",i);
	}
	return 0;
}


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

int main(){
    int n, k, q, i;
    vector<int> a(100000);
    cin >> n >> k >> q;
    for(i = 0;i < q;i++){
        cin >> a.at(i);
    }
    vector<int> point(100000, k-q);
    for(i = 0;i < q;i++){
        point.at(a.at(i)-1)++;
    }

    for(i = 0;i < n;i++){
        if(point.at(i) > 0) cout << "Yes" << endl;
        else cout << "No" <<  endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<class T>T gcd(T a, T b) {if(b==0) return a; return gcd(b, a%b);}

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

int main()
{
    ll a, b;
    while(cin >> a>>b) printf("%lld %lld\n", gcd(a, b), lcm(a, b));
    return 0;}


Measured memory_bytes: 3124
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100005
#define ll long long
using namespace std;
int a[maxn];

int main()
{
    int n,x;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
        ll sum=0;
        for(int i=2;i<=n;i++)
            if(a[i]+a[i-1]>=x)
        {int temp=a[i];
            a[i]=max(0,x-a[i-1]);
            sum+=temp-a[i];

        }
        for(int i=n-1;i>=1;i--)
            if(a[i]+a[i+1]>=x)
        {int temp=a[i];
            a[i]=max(0,x-a[i+1]);
            sum+=temp-a[i];
        }
        printf("%lld\n",sum);
        return 0;
}


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

using namespace std;

int main(){
  int N, tmp;
  int maxi = -1, count = 0, maxi2 = 0;
  cin >> N;
  vector<int> A;
  for (int i=0; i<N; i++){
    cin >> tmp;
    A.push_back(tmp);
    if (maxi < tmp){
      maxi2 = maxi;
      maxi = tmp;
      count = 1;
    }
    else if (maxi == tmp){
      count++;
    }
    else if (maxi2 < tmp){
      maxi2 = tmp;
    }
  }
  
  for (int i=0; i<N; i++){
    cout << ((A[i] == maxi && count == 1) ? maxi2 : maxi) << endl;
  }
  return 0;
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(v) (v.begin(), v.end())
#define ff(i, x, n, k) for(int i=x;i<n;i+=k)
#define rf(i, x, n, k) for(int i=n-1;i>=x;i+=k)
#define ef(i, x, n, k) for(int i=x;i<=n;i+=k)
#define pb push_back
#define eb emplace_back
#define pp pop_back
#define mp make_pair
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define input(n) scanf("%lld", &n)
#define output(n) printf("%lld", n);

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int MOD = 1e9+7;
const ll INF = pow(10, 18)+5;

int main()
{
  fast_cin();
  int a, b;
  cin>>a>>b;
  if(a>9 || b>9)
    cout<<-1<<endl;
  else
    cout<<a*b<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long usg(long long x,long long y) {
    if (x<y)
        swap(x,y);
    if (!(x%y))
        return y;
    return usg(y,x%y);
}
int main() {
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    long long alo=c*d/usg(c,d);
    cout<<(b-a+1)-(b/c-(a-1)/c+b/d-(a-1)/d+(a-1)/alo-b/alo)<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String in = sc.next();
        System.out.println(in.charAt(0) + Integer.toString(in.length() - 2) + in.charAt(in.length() - 1));
    }

}

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

constexpr ll INF = ll(1e+18) + 1;

ll dist(ll a, ll b, ll c, ll d) {
    return abs(a-c) + abs(b-d);
}

int main() {
    int N, K;
    long double ans = 0;
    int j;

    cin >> N >> K;

    rep(i, N) {
        j = 0;
        while((i+1)*pow(2, j) < K) {
            j++;
        }
        ans += 1/(N*pow(2, j));
    }

    cout <<  fixed << setprecision(12) << ans <<endl;
}


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

int main(){
	string str;
 	cin >> str;
 	if (str == "abc" || str == "acb" || str == "bac" || 
        str == "bca" || str == "cab" || str == "cba"){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
	}
}

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

int babbleSort(int A[], int N){
    int sw = 0;
    bool flag = 1;
    for (int i=0;flag;i++){
        flag=0;
        for(int j = N-1;j>=i+1;j--){
            if(A[j] < A[j-1]){
                int a = A[j];
                A[j] = A[j-1];
                A[j-1] = a;
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(){
    int A[100],N,sw;
    cin >> N;
    for (int i=0;i < N; i++){
        cin >> A[i];
    }

    sw = babbleSort(A,N);

    for ( int i= 0; i< N; i++){
        if(i){
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3092
import math
import numpy as np
import numba
import math

n = int(input())

@numba.jit
def main(n):
  lis = np.zeros((n, n, n))
  for i in range(n):
    for j in range(n):
      for k in range(n):
        lis[i][j][k] = math.gcd(math.gcd(i+1, j+1), k+1)
  return int(np.sum(lis))

print(main(n))

Measured memory_bytes: 175808
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            List<String> input = Arrays.asList(br.readLine().split(" "));

            String result = "No";
            if ((input.get(0).equals(input.get(1))
                || input.get(0).equals(input.get(2))
                || input.get(1).equals(input.get(2)))
                && !(input.get(0).equals(input.get(1))
                && input.get(0).equals(input.get(2))
                && input.get(1).equals(input.get(2)))) {
                    result = "Yes";
            }

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;

int ar[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;

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

    cin >> k;
    cout << ar[k - 1] << el;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
char s[10],ss[10];
int main()
{
	scanf("%s%s",&s,&ss);
	if ((s[0]==ss[2])&&(s[1]==ss[1])&&(s[2]==ss[0]))
	  printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rfor(i, a, b) for (int i=a; i<(b); i++)
#define zfor(i, a) for (int i=0; i<(a); i++)
#define brfor(i,a,b) for (int i = (b)-1; i >= a; i--)
#define bzfor(i,a) for (int i = (a)-1; i >= 0; i--)

int main(){
    int n;
    cin>>n;
    ll arr[n];
    ll sum = 0;
    map<ll , ll> mp;
    zfor(i,n){
        cin>>arr[i];
        sum+=arr[i];
        mp[arr[i]]++;
    }
    int t;
    cin>>t;
    while(t--){
        int b , c;
        cin>>b>>c;
        sum -= (mp[b]*b);
        sum+=  (mp[b]*c);
        mp[c]+=mp[b];
        mp[b] = 0; 
        cout<<sum<<"\n";
    }
}

Measured memory_bytes: 10312
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

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


int main(){
  ll x; cin >> x; ll ansa = 0; ll ansb = 0;
  
  for(ll i=-1000; i < 1000; i++){
    for(ll j=-1000; j < 1000; j++){
      if(pow(i,5) - pow(j,5) == x){
        ansa = i;
        ansb = j;
        break;
      }
    }
  }
  
  cout << ansa << ' ' << ansb << endl;
}
  

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

using namespace std;




int main() {
    int L,R,D;
    cin>>L>>R>>D;
    int res = 0;
    for(int c=L;c<=R;c++) {
        if(c%D==0) {
            res++;
        }
    }
    cout<<res;
}


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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e9
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c)
    {
        if (a % 2 == 1)
            cout << 0 << endl;
        else
            cout << -1 << endl;
    }
    else
    {
        int res = 0;
        while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0)
        {
            int x, y, z;
            x = b / 2 + c / 2;
            y = a / 2 + c / 2;
            z = a / 2 + b / 2;
            a = x, b = y, c = z;
            res++;
        }
        cout << res << endl;
    }
}

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

int main() {
	int e, m, a, x;
	double c, d;
	while (true) {
		cin >> e;
		if (e == 0) break;
		m = 90000000;

		c = pow(e, 1.0 / 3.0);
		d = sqrt(e);
		for (int z = 0; z <= c + 100; z++) {
			for (int y = 0; y <= d + 100; y++) {	
				x = e - y*y - z*z*z;
				if (x < 0) break;
				else {
					a = x + y + z;
					if (a < m) m = a;
				}
			}
		}

		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
#include <string.h>
int sub_index(char *first, char *second) {
	int f, s;
	for (f = 0; f < 9; f++) {
		if (first[f] == '1')
			break;
	}
	for (s = 0; s < 9; s++) {
		if (second[s] == '1')
			break;
	}
	return f - s;
}
int main() {
	char blocks[5][11];
	int i, j;
	while (scanf(" %8s", blocks[0]) != EOF) {
		j = strchr(blocks[0], '1') != NULL;
		for (i = 0; i < 7; i++) {
			scanf(" %8s", blocks[j]);
			if (j > 3)
				continue;
			j += strchr(blocks[j], '1') != NULL;
		}
		if (j == 1) {
			puts("C");
		} else if (j == 4) {
			puts("B");
		} else if (j == 2) {
			printf("%c\n", "EAG"[1+sub_index(blocks[0], blocks[1])]);
		} else if (j == 3) {
			printf("%c\n", "FD"[sub_index(blocks[0], blocks[1])]);
		}
	}
	return 0;
}

Measured memory_bytes: 556
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static int N,W,H;
	static Map<String,Page> map;
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		while(true){
			N=cin.nextInt();
			if(N==0)break;
			map=new HashMap<String,Page>();
			W=cin.nextInt();
			H=cin.nextInt();
			Page[] pages=new Page[N];
			for(int i=0;i<N;i++){
				String name=cin.next();
				int cnt=cin.nextInt();
				pages[i]=new Page(name,cnt);
				map.put(name, pages[i]);
				for(int j=0;j<cnt;j++){
					int x1=cin.nextInt();
					int y1=cin.nextInt();
					int x2=cin.nextInt();
					int y2=cin.nextInt();
					pages[i].linkSt[j]=cin.next();
					pages[i].pages[j][0]=x1;
					pages[i].pages[j][1]=y1;
					pages[i].pages[j][2]=x2;
					pages[i].pages[j][3]=y2;
				}
			}
			for(int i=0;i<N;i++){
				pages[i].a();
			}
			Buffer b=new Buffer(pages[0]);
			Buffer head=b;
			for(int cases=cin.nextInt();cases--!=0;){
				String s=cin.next();
//				outputBuff(head);
//				System.out.println("   "+b.now.name);
				if(s.equals("show")){
					System.out.println(b.now.name);
					continue;
				}
				if(s.equals("back")){
					if(b.prev==null)continue;
					b=b.prev;
					continue;
				}
				if(s.equals("forward")){
					if(b.next==null)continue;
					b=b.next;
					continue;
				}
				Page now=b.now;
				int next=now.clicked(cin.nextInt(), cin.nextInt());
				if(next==-1)continue;
				
				b.next=new Buffer(now.link[next]);
				b.next.prev=b;
				b=b.next;
				
			}
		}
		
	}
	static void outputBuff(Buffer b){
		if(b==null)return;
		System.out.println(b.now.name);
		outputBuff(b.next);
	}
	static class Buffer{
		Buffer next;
		Buffer prev;
		Page now;
		Buffer(Page p){
			now=p;
		}
	}
	static class Page{
		String name;
		int[][] pages;
		String[] linkSt;
		Page[] link;
		Page(String s,int cnt){
			name=s;
			pages=new int[cnt][4];
			link=new Page[cnt];
			linkSt=new String[cnt];
		}
		void a(){
			for(int i=0;i<link.length;i++){
				link[i]=map.get(linkSt[i]);
			}
		}
		int clicked(int x,int y){
			for(int i=0;i<link.length;i++){
				if(x<=pages[i][2]&&pages[i][0]<=x&&pages[i][1]<=y&&y<=pages[i][3]){
					return i;
				}
			}
			return -1;
		}
	}
}

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

#define SIZE 10000


bool linerSearch(int A[], int x, int n) 
{
	A[n] = x;
	int i = -1;
	while (A[++i] != A[n]) {}
	return (i != n);
}

int main()
{
	int n, q, result = 0;
	int A[SIZE + 1], T;

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);

	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d", &T);
		if (linerSearch(A, T, n)) result++;
	}
	printf("%d\n", result);
	return 0;
}

Measured memory_bytes: 1228
import sys
input = sys.stdin.readline

X, K, D = map(int, input().split())
X = abs(X)
q = X // D
ans = 0
if q >= K:
    ans = X - K * D
else:
    ans = X - q * D
    K -= q
    if K % 2 == 1:
        ans = D - ans
print(ans)

Measured memory_bytes: 61828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
int gcd(int a,int b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(m),b(m),r(n);
    for (int i = 0; i < n; ++i) {
        r[i] = 0;
    }
    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        r[a[i]-1]++;
        r[b[i]-1]++;
    }
    for (int i = 0; i < n; ++i) {
        cout << r[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
int main(){
  ll n;
  string s;
  cin >> n;
  cin >> s;
  bool can = true;
  if(n % 2 != 0){
    can = false;
  }else{
    rep(i,n/2){
      if(s[i] != s[i + n/2]){
        can = false;
      }
    }
  }
  if(can){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
using namespace std;
signed main(){
  int n,l;
  string s[10000],a;
  cin>>n>>l;
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  sort(s,s+n);
  for(int i=0;i<n;i++){
    cout<<s[i];
  }
  cout<<"\n";
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using ll = long long;
using lint = long long;
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int d,t,s;cin>>d>>t>>s;
	if(t*s>=d){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

int main(){
	int r,s,p;
	cin >> r >> s >> p;
	vector<vector<int> > rinfo(r);
	for(int i=0; i<p; i++){
		int y,x;
		cin >> y >> x;
		y--; x--;
		rinfo[y].push_back((x<s)?s-x-1:x-s);
	}
	for(int i=0; i<r; i++){
		sort(rinfo[i].begin(), rinfo[i].end(), greater<int>());
	}
	int time = 0;
	vector<bool> bs(r+1, 0);
	while(p > 0){
		if(bs[r-1]){
			p--;
		}
		for(int i=r; i>0; i--){
			bs[i] = bs[i-1];
		}
		bs[0] = 0;
		for(int i=0; i<r; i++){
			if(!bs[i] && !rinfo[i].empty() && rinfo[i].back()<=time){
				rinfo[i].pop_back();
				bs[i] = 1;
			}
		}
		time++;
	}
	cout << time << endl;
	return 0;
}


Measured memory_bytes: 5116
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
      	int y = sc.nextInt();
      	boolean ans = false;
		for(int i=0;i<=x;i++){
			if( i*4 + (x-i)*2 == y ){
              ans = true;
            }
		}
      	if( ans ){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
	}
}

Measured memory_bytes: 27052
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

ll ans;

int main(void) {
    ll n, k, mn = 0, mx = 0;
    cin >> n >> k;

    for (ll i=0; i<k; i++) mn += i;
    for (ll i=n; i>=n-k+1; i--) mx += i;

    for (int i=k; i<=n+1; i++) {
        ans += mx - mn + 1;
        ans %= MOD;
        mn += i;
        mx += n - i;
    }
    

    cout << ans % MOD << endl;

	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    //string S;
    cin >> N;
    if(N >= 30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long[][]p = new long[n][2];
		for(int i = 0; i < n; i++) {
			long x = scan.nextLong();
			long y = scan.nextLong();
			long[]t = {x, y};
			p[i] = t;
		}
		scan.close();
		long t = 0;
		for(int i = 0; i <= n - 3; i++) {
			t += triangle(p[i + 2], p[i + 1], p[0]);
		}
		t = Math.abs(t);
		if(t % 2 == 0) {
			System.out.println(t / 2 + ".0");
		}else {
			System.out.println(t / 2 +".5");
		}
	}

	static double triangle(long[]x, long[]y, long[]z) {
		return (cross(vec(z, x), vec(z, y)));
	}
	static long cross(long[]u, long[]v) {
		return u[0] * v[1] - u[1] * v[0];
	}
	static long[] vec(long[]p1, long[]p2) {
		long[]u = {p2[0] - p1[0], p2[1] - p1[1]};
		return u;
	}
}


Measured memory_bytes: 26384
#include<bits/stdc++.h> 
#include<random>  
#define int long long  
#define pp pair<int,int>  
#define ss second  
#define ff first  
#define pb push_back  
#define mod 1000000007  
using namespace std;  
void fastio()  
{    
  
  #ifndef ONLINE_JUDGE                  
  freopen("INPUT.txt","r",stdin);              
  freopen("OUTPUT.txt","w",stdout);              
  #endif    
     ios_base :: sync_with_stdio(false);   
     cin.tie(NULL) ;                             
      cout.tie(NULL);                              
   } 
   
signed main()  {    
        fastio();         
         int t=1;           
          // cin>>t;                
           while(t--)                  
              {                        
                   int n,k,c=0;
                   cin>>n>>k;
                   int a[n];
                   for(int i=0;i<n;i++)
                   {
                   	cin>>a[i];
                   	if(a[i]>=k)
                   	c++;
                   }
                   cout<<c;
               }                    
    }     

Measured memory_bytes: 4408
def resolve():
    n,k=map(int, input().split())
    l=[int(input()) for i in range(n)]
    l.sort()
    a=0
    ans=10**9
    for i in range(n-k+1):
        a=l[i+k-1]-l[i]
        ans=min(a,ans)
    print(ans)
resolve()

Measured memory_bytes: 7384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[1005];
vector<llint> vec[2], avec;
llint sum[2];
bool keep[1005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint p = 0;
	for(int i = 1; i <= n; i++) sum[i%2] += max(0LL, a[i]);
	if(sum[0] < sum[1]) p = 1;
	
	
	llint ans = 0;
	for(int i = n; i >= 1; i--){
		if(i%2 == p && a[i] > 0) keep[i] = true, ans += a[i];
	}
	if(ans == 0){
		llint mx = -inf, mx_i;
		for(int i = 1; i <= n; i++){
			if(mx < a[i]){
				mx = a[i];
				mx_i = i;
			}
		}
		keep[mx_i] = true;
		ans += a[mx_i];
	}
	
	llint l, r;
	for(int i = 1; i <= n; i++){
		if(keep[i]){
			l = i;
			break;
		}
	}
	for(int i = n; i >= 1; i--){
		if(keep[i]){
			r = i;
			break;
		}
	}
	
	for(int i = n; i >= r; i--){
		if(!keep[i]) avec.push_back(i);
	}
	llint cnt = 0;
	for(int i = r; i >= l; i--){
		if(!keep[i]) cnt++;
		else{
			llint x = (cnt+1)/2;
			for(int j = 0; j < x; j++) avec.push_back(i+x-j);
			cnt = 0;
		}
	}
	for(int i = 1; i < l; i++) avec.push_back(1);
	
	cout << ans << endl;
	cout << (int)avec.size() << endl;
	for(int i = 0; i < avec.size(); i++) cout << avec[i] << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M, P;
	cin >> N >> M >> P;
	int A[M], B[M], C[M];
	rep(i,M){
		cin >> A[i] >> B[i] >> C[i];
		--A[i]; --B[i];
		C[i] = P-C[i];
	}
	vector<int> dist(N, INF);
    dist[0] = 0;
	rep(loop,N-1){
		rep(i,M){
            if(dist[A[i]] == INF) continue;
            if(dist[B[i]] > dist[A[i]] + C[i]){
                dist[B[i]] = dist[A[i]] + C[i];
            }
        }
	}
	vector<bool> negativeCycle(N, false); // 負閉路の影響を受ける点(最短経路が-INFに向かう点)をtrueにする。
    rep(loop, N){
        rep(i,M){
            if(dist[A[i]] == INF) continue;
            if(dist[B[i]] > dist[A[i]] + C[i]){
                negativeCycle[B[i]] = true;
            }
            if(negativeCycle[A[i]]) negativeCycle[B[i]] = true;
        }
    }
	if(negativeCycle[N-1]) cout << -1 << endl;
    else cout << max((int)0, -dist[N-1]) << endl;
}

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

int main (void) {

    int x,y,s=0;
    scanf("%d%d",&x,&y);

    for(int c = 0; c<=x; c++) {


        
        
        if(2 * (x -c) +( c * 4 )== y){
        
        printf("Yes");
        s = 0;
        c = x;
        }
        else{ s++;  }

    }
    
if(s++ > 0 || x == 0){printf("No");}
    return 0;
}



Measured memory_bytes: 2152
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    string s;cin>>s;
    REP(i,s.size()){
        if(s[i]=='U'||s[i]=='D')continue;
        if((i+1)%2==0&&s[i]=='L')continue;
        if((i+1)%2==1&&s[i]=='R')continue;
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  int k=b;
  int j=0;
  for(;k>0;k/=10)j++;
  while(j--)a*=10;
  a+=b;
  int jk=0;
  for(int i=0;i*i<=a;i++)if(i*i==a)jk++;
  if(jk)cout<<"Yes";
  else cout<<"No";
  cout<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
double huku(int y,int r){ return pow((1.0+r/100.0),y); }
double tan(int y,int r){ return 1.0+y*r/100.0; }
int main(void)
{
	int n,y,num;
	double ritu,dritu;

	while(1){
		cin >> n;
		if(n==0) break;
		cin >> y;
		vector< vector<int> > bank(n,vector<int>(3));
		for(int i=0;i<n;i++) cin >> bank[i][0] >> bank[i][1] >> bank[i][2]; 
		ritu=0.0;
		for(int i=0;i<n;i++){
			dritu=(bank[i][2]==1?tan(y,bank[i][1]):huku(y,bank[i][1]));
			if(ritu<dritu){
				ritu=dritu;
				num=bank[i][0];
			}
		}
		cout << num << endl;
		bank.clear();
	}
	return 0;
}

Measured memory_bytes: 1220
import sys
from collections import deque

# 最短経路に閉路がくっついているとは限らなかった・・・

read = sys.stdin.read
N, M, *uv, S, T = map(int, read().split())

graph = [[] for _ in range(N + 1)]
for u, v in zip(*[iter(uv)] * 2):
    graph[u].append(v)

INF = 10 ** 15
# [けん,けんけん,けんけんぱ] * (N + 1)
dist = [[INF] * (N + 1) for _ in range(3)]
stack = deque([(0, S)])

while stack:
    cost, v = stack.popleft()
    r = cost % 3
    if dist[r][v] != INF:
        continue
    if r == 0 and v == T:
        print(cost // 3)
        exit()

    dist[r][v] = cost
    for i in graph[v]:
        stack.append((cost + 1, i))
else:
    print(-1)


Measured memory_bytes: 34912
//In the name of Allah
#include <bits/stdc++.h>
using namespace std; 

const int maxN = 1000 * 100 + 100;

int a[maxN];

int main() { 
    int n; cin >> n; 
    for( int i = 0 ; i < n ; i++ ) 
        cin >> a[i]; 
    n = unique( a , a + n ) - a; 
    int ans = 1; 
    for( int i = 2 ; i < n ; i++ ) 
        if( ( a[i-2] < a[i-1] ) != ( a[i-1] < a[i] ) ) { 
            i++; 
            ans++;
        }
    cout << ans << endl;
}


Measured memory_bytes: 640
#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 MOD 1000000007
#define INF (1LL<<57)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_by_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	string s;
	cin>>s;
	int q;
	cin>>q;
	int ok = 0;
	vector<char> bx, ex;
	while(q--)
	{
		int t;
		cin>>t;
		if(t == 1)
		ok ^= 1;
		else
		{
			int f;
			char c;
			cin>>f>>c;
			f--;
			f ^= ok;
			if(f)
			ex.pb(c);
			else bx.pb(c);	
		}	
	}
	reverse(bx.begin(), bx.end());
	string res = "";
	for(auto u : bx)
	res += u;
	res += s;
	for(auto u : ex)
	res += u;	
	if(ok)
	reverse(res.begin(), res.end());
	cout<<res<<"\n";
	return;	
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

Measured memory_bytes: 1448
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

int main(void)
{
    char w[101];
    char tmp;
    int i, j;
    int count = 0;
    bool flag = false;
    scanf("%s", w);
    for (i=strlen(w)-2; i>=0; i--)
    {
        for (j=0; j<=i; j++)
        {
            if (w[j] > w[j+1]) {
                tmp = w[j+1];
                w[j+1] = w[j];
                w[j] = tmp;
            }
        }
    }
    for (i=0; i<=strlen(w)-2; i++)
    {
        count ++;
        if (w[i] != w[i+1] && count%2 != 0) {
            flag = true;
            break;
        }
    }
    if (flag) {
        printf("No\n");
    } else {
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 128
d=input().split()
for o in input():
 s={'N':(0,1,5,4),'W':(0,2,5,3),'E':(0,3,5,2),'S':(0,4,5,1)}[o]
 for i in range(3):d[s[i+1]],d[s[i]]=d[s[i]],d[s[i+1]]
print(d[0])


Measured memory_bytes: 5560
#include<iostream>
#include <bits/stdc++.h>
#include<algorithm>
#include <cstring>
#define endl "\n"
#define SRK ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define EPS 1e-6
#define MAX 100000
typedef long long ll;
const ll MOD = 1e9 + 7;
using namespace std;

int N = 1000000;
int NOD[1000000];
void generateNOD()
{
    for (int i = 0; i <= N; i++)
    {
        for (int j = i; j <= N; j += i)
        {
            NOD[j]++;
        }
    }
}
int main()
{
    int n;
    cin >> n;
    int yen500 = 1000 * (n / 500);
    int left = n % 500;
    int yen5 = 5 * (left / 5);
    cout << yen500 + yen5 << endl;

}


Measured memory_bytes: 3640
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args){



		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int m1 = sc.nextInt();
		int d1 = sc.nextInt();
		int m2 = sc.nextInt();
		int d2 = sc.nextInt();
		
		if(m1<m2) {
			System.out.println(1);
		}else {
			System.out.println(0);
		}
		
	}
}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 21844
import sys
import math

A, B, H, M =list(map(int,input().split()))

thetaH=(H+M/60.0)/6.*math.pi
thetaM=M/30.0*math.pi

theta=abs(thetaH-thetaM)

ans = math.sqrt(A*A + B*B -2.*A*B*math.cos(theta))

print(ans)


Measured memory_bytes: 9372
icase=0
if icase==0:
    n,m=map(int,input().split())
    ab=[[0]*2 for i in range(m)]
    for i in range(m):
        ai,bi=map(int,input().split())
        ab[i]=[ai-1,bi-1]
    ab.sort(reverse=True)
elif icase==1:
    n,m=5,2
    ab=[[1, 4], [0, 3]]
elif icase==2:
    n,m=9,5
    ab=[[6, 8], [3, 5], [2, 4], [1, 6], [0, 7]]
elif icase==3:
    n,m=5,10
    ab=[[3, 4], [2, 4], [2, 3], [1, 4], [1, 3], [1, 2], [0, 4], [0, 3], [0, 2], [0, 1]]

istat=0
icnt=0
while True:
    lower=ab[istat][0]
#    print(istat,lower)
    ii=istat
    while lower<ab[ii][1]:
        ii+=1
        if ii>=m:
            break
    istat=ii
    icnt+=1
    if ii>=m:
        break
    
print(icnt)
        

Measured memory_bytes: 88700
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

vector<vector<int>> d(200005);
bool ans=false;
int n,m;
bool dfs(int cnt, int cur){
    if(cnt==2)return cur == n-1;
    bool f = false;
    rep(i,d[cur].size()){
        if(dfs(cnt+1,d[cur][i]))f=true;
    }
    return f;
}

int main(){
    cin >> n >> m;
    
    rep(i,m){
        int a,b;
        cin >> a >> b;
        --a;--b;
        d[a].push_back(b);
        d[b].push_back(a);
    }
    if(dfs(0,0))cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 12016
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}

int main() {
  ll N;
  cin >>N;
  vl A(N);
  rep(i,N) {
cin >>A.at(i);
  }

  ll sum=0;

  repl(i,1,N) {
if(A.at(i)>=A.at(i-1)) {
continue;
}
else {
sum+=A.at(i-1)-A.at(i);
  A.at(i)=A.at(i-1);
}
  }
    
    
    
    
    
    
  cout<<sum<<endl;
}

Measured memory_bytes: 4836
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
    int H, W;
    
    while (true) {
        cin >> H >> W;
        
        if (H == 0 && W == 0) break;
        
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                cout << "#" << flush;
            }
            cout << endl;
        }
        cout << endl;
    }
}

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

int main() {
    int k,a,b;
    cin>>k;
    if (k%2==0) {
        b=k/2;
        a=b;
    } else {
        b=k/2;
        a=b+1;
    }
    cout<<a*b<<endl;
}   


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

ll N;
ll A, B, C, D;
int T;

void solve(){
    cin >> N >> A >> B >> C >> D;
    map<ll, ll> mp;
    ll ans = linf;
    mp[N] = 0;
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    pq.push({0, N});

    while(!pq.empty()){
        pll p = pq.top(); pq.pop();
        ll t = p.second;
        ll c = mp[t];
        if(c < p.first) continue;
        if(t == 0){
            chmin(ans, c);
            break;
        }
        if((ans / D) + 1 >= t) chmin(ans, c + D * t);
        auto culc = [&](ll num, ll d, ll cost){
            if(mp.find(num / d) == mp.end()) mp[num / d] = linf;
            if(mp[num / d] > cost){
                mp[num / d] = cost;
                pq.push({cost, num / d});
            }
        };
        
        if(t % 2 == 0){
            culc(t, 2, c + A);
        }else{
            culc(t + 1, 2, c + D + A);
            culc(t - 1, 2, c + D + A);
        }

        if(t % 3 == 0){
            culc(t, 3, c + B);
        }else if(t % 3 == 1){
            culc(t - 1, 3, c + D + B);
        }else{
            culc(t + 1, 3, c + D + B);
        }

        if(t % 5 == 0){
            culc(t, 5, c + C);
        }else if(t % 5 == 1){
            culc(t - 1, 5, c + D + C);
        }else if(t % 5 == 2){
            culc(t - 2, 5, c + D * 2 + C);
        }else if(t % 5 == 3){
            culc(t + 2, 5, c + D * 2 + C);
        }else{
            culc(t + 1, 5, c + D + C);
        }
    }
    cout << ans << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> T;
    while(T > 0){
        solve();
        T--;
    }
    return 0;
}

Measured memory_bytes: 4328
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long 
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int mod = 1e9 + 7;
int Mod(int x){x%=mod;if(x<0)x+=mod;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
#define all(x) x.begin(), x.end()
#define db double

int dp[3005][3005] = {0};
 
int__ main() {
	fast;
	int n; cin >> n;
	vi a(n);
 
	for(int i=0;i<n;i++) {cin >> a[i]; dp[i][i] = a[i];}
 
	for(int i=n-1;i>=0;i--) {
		for(int j=i+1;j<n;j++) {
			dp[i][j] = max(a[i] - dp[i+1][j],a[j] - dp[i][j-1]);
		}
	}
 
	cout << dp[0][n-1] << endl;
}



Measured memory_bytes: 49772
N = int(input())
As = list(map(int, input().split()))
Cs = {}
for A in As:
  if A not in Cs:
    Cs[A] = 0
  Cs[A] += 1
#print(Cs)
r0 = 0
for C in Cs.values():
  r0 += C*(C-1)//2
#print(r0)
for A in As:
  C = Cs[A]
  r = r0-C*(C-1)//2+(C-1)*(C-2)//2
  print(r)


Measured memory_bytes: 26140
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000+7;
constexpr long long INF = std::numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, q, last, cnt, ans, sum;
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 } ,{ 0,-1 } };
struct Edge { LL to, cost; };
vector<Edge>vec[10000];
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
struct Combination {
	int mod;
	vector< int64_t > mfact, rfact;

	Combination(int sz, int mod) : mfact(sz + 1), rfact(sz + 1), mod(mod) {
		mfact[0] = 1;
		for (int i = 1; i < mfact.size(); i++) {
			mfact[i] = mfact[i - 1] * i % mod;
		}
		rfact[sz] = inv(mfact[sz]);
		for (int i = sz - 1; i >= 0; i--) {
			rfact[i] = rfact[i + 1] * (i + 1) % mod;
		}
	}

	int64_t fact(int k) const {
		return (mfact[k]);
	}

	int64_t pow(int64_t x, int64_t n) const {
		int64_t ret = 1;
		while (n > 0) {
			if (n & 1) (ret *= x) %= mod;
			(x *= x) %= mod;
			n >>= 1;
		}
		return (ret);
	}

	int64_t inv(int64_t x) const {
		return (pow(x, mod - 2));
	}

	int64_t P(int n, int r) const {
		if (r < 0 || n < r) return (0);
		return (mfact[n] * rfact[n - r] % mod);
	}

	int64_t C(int p, int q) const {
		if (q < 0 || p < q) return (0);
		return (mfact[p] * rfact[q] % mod * rfact[p - q] % mod);
	}

	int64_t H(int n, int r) const {
		if (n < 0 || r < 0) return (0);
		return (r == 0 ? 1 : C(n + r - 1, r));
	}
};
int main() {
	cin >> n;
	n--;
	Combination comb(n+2, MOD);
	for (int i = 1; i <= n; i++) {
		ans +=((((comb.mfact[i] * comb.C(i - 1, n - i) % MOD)* comb.mfact[n - i]%MOD
			- (comb.mfact[i - 1] * comb.mfact[n - i + 1] % MOD) * comb.C(i - 2, n - i + 1)%MOD) % MOD)+MOD) * i;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 16128