akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    ll res = (n + 1) / 2;
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N;
  get(N);
  int last = 0;
  FOR(i, N) {
    int H;
    cin >> H;
    if (last < H) {
      last = H - 1;
    } else if (last == H) {
      last = H;
    } else {
      print("No");
      return 0;
    }
  }
  print("Yes");
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
	static List<Integer> path;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		Map<Integer, List<Hen>> map = new HashMap<Integer, List<Hen>>();
		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			Hen h = new Hen();
			h.a = Integer.parseInt(sa[0]) - 1;
			h.b = Integer.parseInt(sa[1]) - 1;
			h.c = Integer.parseInt(sa[2]);

			List<Hen> list = map.get(h.a);
			if (list == null) {
				list = new ArrayList<Hen>();
				map.put(h.a, list);
			}
			list.add(h);
		}
		br.close();

		long val = 100000000000000L;
		long val2 = 10000000000000L;
		boolean[][] used = new boolean[n][n];
		long[] score = new long[n];
		ArrayDeque<Integer> que = new ArrayDeque<Integer>();
		que.add(0);
		while (!que.isEmpty()) {
			Integer cur = que.pollLast();
			List<Hen> list = map.get(cur);
			if (list != null) {
				for (Hen h : list) {
					if (used[h.a][h.b]) {
						if (score[h.b] < val2) {
							if (score[h.b] < score[cur] + h.c) {
								que.add(h.b);
								score[h.b] = val;
							}
						}
					} else {
						que.add(h.b);
						used[h.a][h.b] = true;
						score[h.b] = score[cur] + h.c;
					}
				}
			}
		}

		if (score[n - 1] >= val2) {
			System.out.println("inf");
		} else {
			System.out.println(score[n - 1]);
		}
	}

	static class Hen {
		int a, b, c;
	}
}


Measured memory_bytes: 25812
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long ll;


typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

vector<int> G[100005];
std::vector<P> tree[100010];

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

ll i,j,k,l,ii,jj;
ll n,m;
ll x;
bool flag=false;
bool used[200005];
ll a[200005];
ll num=0;

int main(){
    
    cin>>n>>x;
    for(i=1;i<=200001;i++){
        used[i]=false;
    }
    if (x==1 || x==2*n-1){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
        
        if(x==2*n-2){
            flag=true;
            x=2;
        }
        
        used[1]=used[x]=used[2*n-2]=used[2*n-1]=true;
        num=0;
        for(i=1;i<=n*3;i++){
            if(!used[i]){
                num++;
                used[i]=true;
                a[num]=i;
            }
            if(num==n-3)break;
        }
        a[n-2]=2*n-2;
        a[n-1]=1;
        a[n]=x;
        a[n+1]=2*n-1;
        num = n+1;
        for(i=1;i<=3*n;i++){
            if(!used[i]){
                num++;
                used[i]=true;
                a[num]=i;
            }
            if(num>=2*n-1)break;
        }
        if(!flag){
            for(i=1;i<=2*n-1;i++){
                cout<<a[i]<<endl;
            }
        }else{
            for(i=1;i<=2*n-1;i++){
                cout<<2*n-a[i]<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define fastIO ios::sync_with_stdio(0); cin.tie(NULL);
typedef long long ll;
using namespace std;


int main(){
    fastIO
    ll a[4];
    for(int i=0; i<4; i++)
      cin>>a[i];
    ll x = a[0]*a[2];
    ll y = a[0]*a[3];
    ll z = a[1]*a[2];
    ll c = a[1]*a[3];
    
    cout<<max(max(x,y),max(z,c));
    return 0;
}

Measured memory_bytes: 3648
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var r = int.Parse(line[1]);
        var t = int.Parse(line[2]);
        var p = new int[n];
        for (int i = 0; i < n; i++) p[i] = int.Parse(Console.ReadLine().Trim());
        var ans = goSim(n, r, t, p);
        Console.WriteLine(ans);
    }
    static int goSim(int n, int r, int t, int[] p)
    {
        var np = new int[r];
        var up = new int[r];
        var pp = new int[r];
        var ans = n;
        for (int i = 0; i < n; i++)
        {
            pp[i] = p[i];
            if (pp[i] >= r) pp[i] %= r; ;
        }
        var tt = 1;
        while (tt < t)
        {
            var plist = new List<int>();
            for (int i = 0; i < n; i++)
            {
                pp[i] += p[i];
                if (pp[i] >= r) pp[i] %= r;
                var ppi = pp[i];
                if (!plist.Contains(ppi)) plist.Add(ppi);
                up[ppi]++;
                if (np[ppi] >= 1) np[ppi]--;
                else ans++;
            }
            foreach (var x in plist)
                if (up[x] > 0) { np[x] += up[x]; up[x] = 0; }
            tt++;
        }
        return ans;
    }
}



Measured memory_bytes: 17876
#include <stdio.h>
int main()
{   int n,t;
    scanf("%d%d",&n,&t);
    int a[n];
    scanf("%d",&a[0]);
    long long ans=0;
    for(int i=1;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]-a[i-1]>=t){
            ans+=t;
        }else{
            ans+=(a[i]-a[i-1]);
        }
    }
    ans+=t;
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 896
import java.io.*;
import java.util.*;
public class Main {
  public static void main(String[] args) throws Exception {
    String line = null;
    long sum = 0L;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    line = br.readLine();
    String data[] = line.split(" ");
    long n = Long.parseLong(data[0]);
    long x = Long.parseLong(data[1]);
    //System.out.println("N=" + n + ",X=" + x);
    long a = 0L; // 短辺の長さ
    long b = 0L; // 長辺の長さ
    long c = 0L; // 正三角形の数
    long d = 0L; // 長辺の残り
    long cnt = 0L;

    while (true) {
      if (cnt == 0L) {
        if (x >= (n - x)) {
          a = n - x;
          b = x;
        } else {
          a = x;
          b = n - x;
        }
      } else {
        b = a;
        a = d;
      }
      c = b / a;
      d = b % a;
      sum = sum + (c * 3L * a);
      //System.out.println("a=" + a + ",b=" + b + ",c=" + c + ",d=" + d + ",sum=" + sum);
      if (d == 0L) {
        break;
      }
      cnt = cnt + 1L;
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 20948
#include<stdio.h>
int main(){
  int N=0;
  int K=0;
  int count=0;
  scanf("%d",&N);
  scanf("%d",&K);
  int h[N];
  for(int i=0;i<N;i++){
    scanf("%d",&h[i]);
  }
  for(int i=0;i<N;i++){
    if(h[i]>=K){
      count++;
    }
  }
  printf("%d\n",count);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

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

  ll rs =0,gs=0,bs=0;
  for(auto v : s) {
    if(v=='R') rs++;
    if(v=='G') gs++;
    if(v=='B') bs++;
  }
  ll ans = rs* bs*gs;
  if (ans==0) {
    cout << '0' << endl;
    return 0;
  }

  rep(j,n) {
    orep(i,n/2) {
      if(j+i+i >= n) continue;
      if(s[j] != s[j+i] and s[j+i]!=s[j+i+i] and s[j]!=s[j+i+i]) {
        ans--;
      }
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3648
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

signed main()
{
    IOS;
    double R;

    cin>>R;

    cout<<fixed<<setprecision(20)<<2*3.14159265358979*R<<endl;    
    
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;


bool compare(const string &a,const string &b){
    return a<b;
}


int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>s1>>s2;

	sort(s1.bb,s1.ee);
	sort(s2.bb,s2.ee);

	reverse(s2.bb,s2.ee);


	(s1<s2)?cout<<"Yes"<<endl:cout<<"No"<<endl;



}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main()
{
    ll N, M;
    cin >> N >> M;
    ll ans = 0;
    if (N - M > 1 || M - N > 1)
    {
        // 0通りなのでなにもしない
    }
    else
    {
        ans = 1;
        // 条件を満たす列をつくることができるのは
        // N = M か
        // |N - M| = 1のとき
        if (N == M)
        {
            for(ll i = 1; i <= N; ++i)
            {
                ans = ans * i % MOD;
            }
            for(ll i = 1; i <= M; ++i)
            {
                ans = ans * i % MOD;
            }
            // 犬と猿のどちらが先頭かで2通りある
            ans = ans * 2 % MOD;
        }
        // |N - M| = 1は1頭多い方が先頭になる
        else
        {
            for(ll i = 1; i <= N; ++i)
            {
                ans = ans * i % MOD;
            }
            for(ll i = 1; i <= M; ++i)
            {
                ans = ans * i % MOD;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import defaultdict

n, m = map(int ,input().split())
drinks = defaultdict(int)

for _ in range(n):
    a, b = map(int, input().split())
    drinks[a] += b

ans = 0
sorted_drinks = sorted(drinks.items(), key=lambda x:x[0])

for a, b in sorted_drinks:
    cnt = min(m, b)
    ans += a * cnt
    m -= cnt
    if m == 0:
        break
print(ans)    


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

auto chmin = [](auto&& l, auto r) { return r < l ? l = r, 1 : 0; };

template <class T> struct dijkstra {
  struct edge {
    int to;
    T w;
  };
  vector<vector<edge>> g;
  const T inf;
  dijkstra(int n, T _inf = numeric_limits<T>::max()) : g(n), inf(_inf) {}
  void add_edge(int from, int to, T w) { g[from].push_back({to, w}); }
  void add_undirected_edge(int u, int v, T w) {
    add_edge(u, v, w), add_edge(v, u, w);
  }
  vector<T> run(int s) const {
    vector<T> dist(g.size(), inf);
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<>> pq;
    pq.emplace(dist[s] = 0, s);
    while (not pq.empty()) {
      T d;
      int v;
      tie(d, v) = pq.top(), pq.pop();
      if (d > dist[v]) continue;
      for (auto e : g[v])
        if (chmin(dist[e.to], dist[v] + e.w)) pq.emplace(dist[e.to], e.to);
    }
    return dist;
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w;
  while (cin >> w >> h, h) {
    vector<string> s(h);
    int n = 0;
    for (int i = 0; i < h; ++i) {
      cin >> s[i];
      for (int j = 0; j < w; ++j) {
        if (s[i][j] == '*') {
          s[i][j] = '0' + n++;
        }
      }
    }
    auto in = [&](int i, int j) {
      return 0 <= i and i < h and 0 <= j and j < w;
    };
    auto $ = [&](int i, int j, int bt) {
      return i * w * (1 << n) + j * (1 << n) + bt;
    };
    dijkstra<int> g(h * w * (1 << n));
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (s[i][j] == 'x') {
          continue;
        }
        for (int di = -1; di <= 1; ++di) {
          for (int dj = -1; dj <= 1; ++dj) {
            if (abs(di) + abs(dj) == 1) {
              int ni = i + di, nj = j + dj;
              if (not in(ni, nj) or s[ni][nj] == 'x') {
                continue;
              }
              for (int bt = 0; bt < 1 << n; ++bt) {
                g.add_edge($(i, j, bt), $(ni, nj, isdigit(s[ni][nj]) ? bt | 1 << (s[ni][nj] - '0') : bt), 1);
              }
            }
          }
        }
      }
    }
    int res = g.inf;
    for (int si = 0; si < h; ++si) {
      for (int sj = 0; sj < w; ++sj) {
        if (s[si][sj] == 'o') {
          auto d = g.run($(si, sj, 0));
          for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
              chmin(res, d[$(i, j, (1 << n) - 1)]);
            }
          }
        }
      }
    }
    if (res == g.inf) {
      res = -1;
    }
    cout << res << '\n';
  }
}



Measured memory_bytes: 15440
//-------------
//include
//-------------
#include <map>
#include <list>
#include <cmath>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
//-------------
//typedef
//-------------
typedef  long long LL;
typedef  vector<int> VI;
typedef  vector<double> VD;
typedef  string STR;
typedef  pair<int, int> PII;
typedef  vector<int, int> VII;
typedef  map<string, int> MSI;
//-------------
//utillty
//-------------
#define ALL(a)  (a).begin(),(a).end()
#define MK make_pair
#define PB push_back
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(a) cout<<a<<endl
#define POW2(a) pow(a, 2.0)
//-------------
//repetition
//-------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//-------------
//debug
//-------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumpl(c) REP(i,SZ(c))cerr<<#c<<i<<"="<<(c[i])<<endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int MOD = 1000000007;
int main()
{
	STR A;
	cin >> A;
	REP(i,SZ(A))
	{
		cout << A[SZ(A)-1-i];
	}
	cout<<endl;
#ifdef _DEBUG
	while(1);
#endif // _DEBUG

	return 0;
}

Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A, B , C;
    cin >> A >> B >> C;
    int a = max(A,max(B,C));
    int c = min(A,min(B,C));
    int b = A + B + C - a - c;
    if((2*a - b - c )%2== 0){
        cout << (2*a - b - c)/2;
    }else{
        cout << (2*a - b - c - 1)/2 + 2 ;
    }
return 0;
}


Measured memory_bytes: 256
// for(auto it:m)
//     {
//         cout<<it.second;
//     }
// }
 
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
 
 
int main()
{
      int n,s=0;
      cin>>n;
      int d[n];
      for(int i=0;i<n;i++)
      {
          cin>>d[i];
      }
      for(int i=0;i<n;i++)
      {
          for(int j=i;j<n;j++)
          {
              if(i!=j)
              {
                  s = s + d[i]*d[j];
              }
          }
      }
      cout<<s;

}
 

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

signed main(){
  int N,L,T;
  cin>>N>>L>>T;
  std::vector<int> v(N),w(N),an(N);
  for(int i=0;i<N;i++)cin>>v[i]>>w[i];
  for(int i=0;i<N;i++){
    if(w[i]==1)an[i]=(v[i]+T)%L;
    else an[i]=(v[i]-(T%L)+L)%L;
  }
  int kk=0;
  int o=0;
  int po=an[0];
  sort(an.begin(),an.end());
  if(w[0]==1){
    for(int i=1;i<N;i++){
      if(w[i]==2){
        if(v[i]-v[0]<=T*2)kk++;
        kk+=max((T*2-(v[i]-v[0]))/L,o);
        kk%=N;
      }
    }
    for(o=N-1;o>=0;o--)if(an[o]==po)break;
    //now o is kk's position
    for(int i=0;i<N;i++){
      cout<<an[(o-kk+i+N)%N]<<endl;
    }
  }
  else{
    for(int i=1;i<N;i++){
      if(w[i]==1){
        if(v[0]+L-v[i]<=T*2)kk++;
        kk+=max((T*2-(v[0]+L-v[i]))/L,o);
        kk%=N;
      }
    }
    for(o=0;o<N;o++)if(an[o]==po)break;
    //now o is N-kk's position
    for(int i=0;i<N;i++){
      cout<<an[(o+i+kk)%N]<<endl;
    }
  }
}


Measured memory_bytes: 3584
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<utility>
#include<string>
#include<map>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
ll gcd(int a, int b){return b ? gcd(b, a%b) : a;}
ll lcm(int a, int b){return a*b / gcd(a, b);}
const ll MAX = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<Pll> p(n);
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        p[i] = make_pair(a, b);
    }

    reverse(p.begin(), p.end());
    ll add = 0, ans = 0;
    for(auto x : p){
        ll rem = (x.first+add)%x.second;
        if(rem == 0) continue;

        ll shortage = x.second-rem;
        // cout << "short: " << shortage << "\n";
        ans += shortage;
        add += shortage;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4780
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int f(int x, int y) {return x*x+y*y;}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (1) {
        int h,w; cin >> h >> w;
        if (h+w==0) break;
        int ansh = 1e9, answ = 1e9;
        int val = 1e9;
        for (int i = 1; i <= 150; ++i) {
            for (int j = i+1; j <= 150; ++j) {
                if (i == h && j == w) continue;
                if (f(i,j) < f(h,w) || (f(i,j) == f(h,w) && i < h)) continue;
                if (val < f(i,j)) continue;
                if (val == f(i,j) && ansh < i) continue;
                val = f(i,j);
                ansh = i;
                answ = j;
            }
        }

        cout << ansh << " " << answ << ln;
    }
}



Measured memory_bytes: 3132
#include<stdio.h>

int main(void){
    int n,i,j,a,b;
    char command[20],str[2000],s[2000];

    scanf("%s",str);
    scanf("%d",&n);

    for(j = 0;j < n;j++){
        scanf("%s",command);
        scanf("%d%d",&a,&b);

        if(command[2] == 'i'){
            for(i = 0;i <= b - a;i++)
                s[i] = str[a + i];
            s[i] = '\0';
            printf("%s\n",s);
        }else if(command[2] == 'p'){
            scanf("%s",s);
            for(i = 0;i <= b - a;i++)
                str[a + i] = s[i];
        }else{
            for(i = 0;i <= b - a;i++)
                s[i] = str[b - i];
            for(i = 0;i <= b - a;i++)
                str[a + i] = s[i];
        }
    }
    return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << '=' << x << '\n'
const long long MOD=1e9+7;
//const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?'\n':' ');
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}

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

const int MAX=9e3;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X; cin >> X;
    map<ll,ll> m,n;
    for (ll i=0;i<=MAX;++i){
        m[i]=i*i*i*i*i,n[i*i*i*i*i]=i;
        m[-i]=-m[i],n[-i*i*i*i*i]=-i;
    }
    for (ll i=0;i<=MAX;++i){
        ll B=m[i]-X;
        if (n.count(B)){
            cout << i << ' ' << n[B] << '\n';
            return 0;
        }
    }
}

Measured memory_bytes: 5900
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e10
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<lli>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> bool chmax(T &a, T &b){ if(a<b) { a=b; return 1; }}
template<typename T> bool chmin(T &a, T &b){ if(b<a) { a=b; return 1; }}
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


int h, w;
int g[100][100];
queue<pair<int, int>> q;
int visit[100][100];

int bfs(){
    q.push(make_pair(0, 0));
    int res = 0;
    bool flg = false;

    while(!q.empty()){
        pair<int, int> e = q.front();
        q.pop();
        //visit[e.first][e.second] = 1;

        int x = e.first;
        int y = e.second;

        if(x == w-1 && y == h-1){
            res = visit[x][y] + 1;
            flg = true;
            break;
        }

        rep(i, 4){
            int deltax = x + dx[i];
            int deltay = y + dy[i];
            if(deltax < 0 || deltax >= w || deltay < 0 || deltay >= h) continue;
            if(visit[deltax][deltay] > 0) continue;
            if(g[deltax][deltay] == 0) continue;

            q.push(make_pair(deltax, deltay));
            visit[deltax][deltay] = visit[x][y] + 1;
        }
    }

    if(!flg){
        return -1;
    }

    return res;
}

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

    char tmp;
    int cnt = 0;
    cin >> h >> w;
    rep(i, h){
        rep(j, w){
            cin >> tmp;
            g[j][i] = (tmp=='.');
            if(tmp=='#') cnt++;
        }
    }

    int res = bfs();

    if(res == -1){
        cout << -1 << endl;
        return 0;
    }

    cout << (h*w)-res-cnt << endl;

    return 0;
}

Measured memory_bytes: 384
// unihernandez22
// https://atcoder.jp/contests/abc076/tasks/abc076_c
// string manipulation

import std.stdio;
import std.string;
void main() {
	string s = readln.chomp;
	string t = readln.chomp;

	ulong idx = -1;
	bool matched;
	foreach(i; 0..(s.count-t.count)+1) {
		if (s[i] == '?' || s[i] == t[0]) {
		matched = true;
		foreach(j; 0..t.count) {
			if (s[i+j] != '?' && s[i+j] != t[j]) {
				matched = false;
				break;
			}
		}
		if (matched)
			idx = i;
		}
	}
	if (idx == -1) {
		writeln("UNRESTORABLE");
		return;
	}
	foreach(i; 0..s.count) {
		if (s[i] == '?' && (i < idx || i >= t.count+idx))
			write("a");
		else if (s[i] == '?')
			write(t[i-idx]);
		else
			write(s[i]);
	} writeln;
}


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

using namespace std;

typedef long long ll;

int main(){
ll N,Q; cin >> N >> Q;
  vector<pair<ll,pair<ll,ll> >> event_sort;
  for(ll i = 0 ; i < N; i++){
    ll s,t,x; cin >> s >> t >> x;
    event_sort.push_back(make_pair(s-x,make_pair(-1,x)));
    event_sort.push_back(make_pair(t-x,make_pair(0,x)));}
  
    for(ll j = 0; j < Q; j++){
      ll d; cin >> d;
      event_sort.push_back(make_pair(d,make_pair(1,j)));}
    
    sort(event_sort.begin(),event_sort.end());
    
    multiset<ll> mp;
    
    vector<ll> answer(Q,0);
    
    for(ll i = 0; i < (int) event_sort.size(); i++){
      ll p,q,r;
      p = event_sort[i].first;
      q = event_sort[i].second.first;
      r = event_sort[i].second.second;
      if( q == -1){ 
        mp.insert(r);}
      else if( q == 0){
        mp.erase(mp.lower_bound(r));}
      else{
        if( mp.empty()){ answer[r] = -1;}
        else{
        answer[r] = *(mp.begin());}} }
    
    for(ll i = 0; i < Q; i++){
      cout << answer[i] <<endl; }
    return 0;}
        
      

Measured memory_bytes: 27876
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL K;
std::vector<LL>ans;

LL f(LL n)
{
	LL res = 0;
	while (n > 0)
	{
		res += n % 10;
		n /= 10;
	}
	return res;
}

int main()
{
	in >> K;
	for (LL i = 0; i <= 15; ++i)
	{
		for (LL j = 1; j <= 150; ++j)
		{
			if (i == 0 && j == 1) continue;
			LL tmp = j * pow(10LL, i);
			--tmp;
			ans.push_back(tmp);
		}
	}
	std::sort(ans.begin(), ans.end());
	ans.erase(std::unique(ans.begin(), ans.end()), ans.end());
	rep(i, ans.size())
	{
		for (int j = i + 1; j < ans.size(); ++j)
		{
			if ((long double)ans[i] / f(ans[i]) > (long double)ans[j] / f(ans[j]))
			{
				ans.erase(ans.begin() + i);
				--i;
				break;
			}
		}
	}
	rep(i, K) out << ans[i] << std::endl;
	return 0;
}


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

int GetDigit(int num)
{
    int digit = 0;
    while (num != 0)
    {
        num /= 10;
        digit++;
    }
    return digit;
}

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int dig = GetDigit(i);
        if (dig == 1 || dig == 3 || dig == 5)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a;
	cin>>b;
	cin>>c;
	if (a<b&&b<c&&a<c){
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<string> v;
string s;
void f(int n, char mx) {
	if(!n) {
		v.push_back(s);
		return;
	}
	for(char c='a'; c<=mx+1; c++) {
		s.push_back(c);
		f(n-1, max(c, mx));
		s.pop_back();
	}
}
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	s = "a";
	f(n-1, 'a');
	for(string &t: v)
		cout << t << '\n';
}

Measured memory_bytes: 9716
#include <bits/stdc++.h>
using namespace std;
long long N, K, p = 1000000007;
long long pow_mod(long long a, long long b) {
    if (b == 0) return 1;
    long long k = pow_mod(a, b/2);
    long long kk = (k * k) % p;
    if (b & 1) return (kk * a) % p;
    return kk;
}
long long h[5000];
long long nCr (long long n, long long r) {
    long long X = h[n], Y = (h[r]*h[n-r]) % p;
    return (X * pow_mod(Y, p-2)) % p;
}
int main () {
    h[0] = h[1] = 1;
    for (int i = 2; i < 5000; i++) {
        h[i] = h[i-1] * i;
        h[i] %= p;
    }
    cin >> N >> K;
    long long B = K, R = N-K;
    long long l;
    if (B-1 <= R) {
        l = K;
    }
    else {
        l = R+1;
    }
    for (int i = 1; i <= l; i++) {
        auto r = R, b = B;
        r -= i-1;
        b -= i;
        cout << (nCr(r+i, r) * nCr(b+(i-1), b)) % p << endl;
    }
    for (int i = l+1; i <= K; i++) {
        puts("0");
    }
    
}

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

int main(){
    string a,b;
    cin>>a>>b;
    string s=a+b;
    int i=stoi(s);
    for(int j=1;j<i;j++){
        if(j*j==i){
            cout<<"Yes"<<endl;
            break;
        }else if(j+1==i){
            cout<<"No"<<endl;
        }
    }
            
    
    return 0;
}

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

int main()
{
    int n, arr[MAX], cnt = 0;

    scanf("%d", &n);

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

    int idx = 101;

    for(int i = 0; i < n - 1; i++){
        if(arr[i] == arr[i+1]){
            arr[i+1] = idx++;
            cnt++;
        }
    }

    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int h1, s1, h2, s2;
    cin >> h1 >> s1 >> h2 >> s2;
    int winner = 0;
    while (h1 > 0 && h2 > 0) {
        h2 -= s1;
        if (h2 <= 0) {
            winner = 1;
            break;
        }
        h1 -= s2;
        if (h1 <= 0) {
            winner = 2;
            break;
        }
    }

    cout << (winner == 1 ? "Yes" : "No") << endl;
    return 0;
};


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using PP = pair<int, int>;
int n, m;
vector<int> g[100000];
int ans[100000];
int main() {
  cin >> n >> m;
  for (int j = 0; j < m; ++j) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  fill(ans, ans + n, -1);
  queue<PP> q;
  q.push(PP(0, 0));
  while (!q.empty()) {
    auto [from, prev] = q.front(); q.pop();
    if (ans[from] != -1) continue;
    ans[from] = prev;
    for (int to : g[from]) {
      q.push(PP(to, from));
    }
  }
  
  cout << "Yes" << endl;
  for (int i = 1; i < n; ++i) {
    cout << ans[i] + 1 << endl;
  }
  cout << endl;
  
}

Measured memory_bytes: 12080
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  cin >> N;
  
  string S;
  cin >> S;
  
  int num = 0;
  
  for(int i = 0;i < N - 2;++i){
    if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C'){
      num++;
    }
  }
  
  cout << num << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

#define MAX 100000

struct Node{
	int key;
	struct Node *prev,*next;
};

struct Node *nil;

void init(){
	nil=(struct Node *)malloc(sizeof (struct Node));
	nil->next=nil;
	nil->prev=nil;
}

struct Node* search(int key){
	struct Node *c;
	c=nil->next;
	while(c->key!=key){
		c=c->next;
		if(c==nil){
			return (nil);
		}
	}
	return(c);
}

void insert(int key){
	struct Node* x;
	x=(struct Node *)malloc(sizeof (struct Node));

	x->key=key;
	x->next=nil->next;
	x->next->prev=x;
	nil->next=x;
	x->prev=nil;
}

void delete(struct Node * x){
	if(x==nil){
		return;
	}
	x->next->prev=x->prev;
	x->prev->next=x->next;
	free(x);
}

void deleteFirst(){
	delete(nil->next);
}

void deleteLast(){
	delete(nil->prev);
}

void printList(){
	struct Node *c;
	c=nil->next;
	while(c!=nil){
		printf("%d",c->key);
		c=c->next;
		if(c!=nil){
			printf(" ");
		}
	}
	printf("\n");
}

int main(){
	int i,n,key;
	char com[20];
	struct Node *c;

	scanf("%d",&n);
	init();
	for(i=0; i<n; i++){
		scanf("%s",com);
		if(com[0]=='i'){
			scanf("%d",&key);
			insert(key);
		}else if(com[0]=='d'){
			if(strcmp(com,"deleteFirst")==0){
				deleteFirst();
			}else if(strcmp(com,"deleteLast")==0){
				deleteLast();
			}else{
				scanf("%d",&key);
				c=search(key);
				delete(c);
			}
			
		}
	}
	printList();
	
	return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    ll a, b, n;
    cin >> a >> b >> n;
    ll m = 0, x = min(b-1, n), res = -1, count = 0;
    while (x >= 0) {
        res = a * x / b - a * (x / b);
        if (count > a) break;
        m = max(m, res);
        --x; ++count;
    }
    cout << m << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "YES" : "NO"));}
//----------------------------------------------------------------
int divi[1001];

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

  bool cango[n][n];
  rep(i,n){
    rep(j,n){
      cango[i][j]=false;
    }
  }

  rep(i,m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    cango[a][b]=true;
    cango[b][a]=true;
  }

  vec v;
  rep(i,n-1){
    v.pb(i+1);
  }

  int ans=0;
  do {
    rep(i,v.size()){
      int from, to;
      if(i==0) from=0;
      else from=v[i-1];
      to=v[i];
      if(!cango[from][to]) break;
      if(i==v.size()-1) ans++;
    }
  } while (next_permutation(all(v)));

  prt(ans);
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.length() < 5) {
            System.out.println("NO");
            return;
        }
        String[] ary = {"dreamer", "eraser", "dream", "erase"};
        Set<String> set = new LinkedHashSet<>(Arrays.asList(ary));
        int idx = s.length() - 1;
        while (idx >= 0) {
            boolean isMatch = false;
            if (idx - 6 >= 0) {
                isMatch = set.contains(s.substring(idx - 6, idx + 1));
                if (isMatch) {
                    idx -= 7;
                }
            }
            if (!isMatch && idx - 5 >= 0) {
                isMatch = set.contains(s.substring(idx - 5, idx + 1));
                if (isMatch) {
                    idx -= 6;
                }
            }
            if (!isMatch && idx - 4 >= 0) {
                isMatch = set.contains(s.substring(idx - 4, idx + 1));
                if (isMatch) {
                    idx -= 5;
                }
            }
            if (!isMatch) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}

Measured memory_bytes: 26232
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
const int inf = 0x3f3f3f3f;
int N, K;
int h[maxn];
int dp[maxn];
int main()
{
    scanf("%d%d", &N, &K);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d", &h[i]);
    }
    memset(dp, inf, sizeof(dp));
    dp[1] = 0;
    for(int i = 1; i <= N; i++)
    {
        for(int j = 1; j <= K; j++)
        {
            if(i + j <= N) dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }
    printf("%d\n", dp[N]);
    return 0;
}




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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  int maxL =0;
  int minR =100000;
  for (int i =0; i<M; i++) {
    cin >> L.at(i);
    cin >> R.at(i);
    maxL = max(L.at(i),maxL);
    minR = min(R.at(i),minR);
  }
  
  if (minR - maxL >= 0) {
    cout << minR - maxL + 1 << endl;
  } else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 4032
#include <iostream>
#include <iterator>
#include <cstdio>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <chrono>
#include <functional>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No")
	{
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	int ncr(int left, int right)
	{
		right = min(left - right, right);
		int ans = 1;
		for (int i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;


int main()
{
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int vx = x2 - x1;
	int vy = y2 - y1;
	cout << x2 - vy << " " << y2 + vx << " " << x1 - vy << " " << y1 + vx << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#define Inf 10000000
#define ll long long
using namespace std;

int dp[222222];

int nextocc[26][222222];

int main() {
    string A;
    cin>>A;
    
    
    
    int L=A.size();
    
    for(int c=0;c<26;c++)
        nextocc[c][L]=-1;
    
    for(int j=L-1;j>=0;j--) {
        for(int c=0;c<26;c++) {
            if (A[j]==c+'a') {
                nextocc[c][j]=j;
            } else {
                nextocc[c][j]=nextocc[c][j+1];
            }
        }
    }
    
    for(int j=L;j>=0;j--) {
        dp[j]=Inf;
        for(int c=0;c<26;c++) {
            // first occurrence of c >= j
            if (nextocc[c][j]==-1) {
                dp[j]=1;
            } else {
                dp[j]=min(dp[j], 1 + dp[nextocc[c][j]+1]);
            }
        }
    }
    
    int pos=0;
    string ans;
    while(1) {
        // dp[pos]
        bool done=false;
        for(int c=0;c<26;c++) {
            if (nextocc[c][pos]==-1) {
                ans.push_back(c+'a');
                done=true;
                break;
            } else if (1 + dp[nextocc[c][pos]+1] == dp[pos]) {
                ans.push_back(c+'a');
                pos=nextocc[c][pos]+1;
                break;
            }
        }
        if (done)
            break;
    }
    
    cout << ans << endl;
    
    
    
}

Measured memory_bytes: 23812
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int n,k;
vector<vector<int>> g(4010,vector<int>(4010,0)),cnt(4010,vector<int>(4010,0));

int get(int x1,int y1,int x2,int y2){
  int ret=cnt[x2][y2];
  if(x1>0) ret-=cnt[x1-1][y2];
  if(y1>0) ret-=cnt[x2][y1-1];
  if(x1>0 && y1>0) ret+=cnt[x1-1][y1-1];
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>k;
  rep(i,n){
    ll x,y;
    char c;
    cin>>x>>y>>c;
    if(c=='W') y+=k;
    x%=2*k;
    y%=2*k;
    g[x][y]++;
  }
  rep(i,4*k)rep(j,4*k){
    if(i<2*k && j<2*k) continue;
    g[i][j]=g[i%(2*k)][j%(2*k)];
  }
  rep(i,4*k)rep(j,4*k){
    cnt[i][j]=g[i][j];
    if(i>0) cnt[i][j]+=cnt[i-1][j];
    if(j>0) cnt[i][j]+=cnt[i][j-1];
    if(i>0 && j>0) cnt[i][j]-=cnt[i-1][j-1];
  }
  int ans=0;
  rep(i,2*k)rep(j,2*k) ans=max(ans,get(i,j,i+k-1,j+k-1)+get(i+k,j+k,i+2*k-1,j+2*k-1));
  cout<<ans<<endl;
}

Measured memory_bytes: 126208
n,k=map(int,input().split())
mod=10**9+7
ans=0
for i in range(k,n+2):
  maxi=n*(n+1)//2-(n-i)*(n-i+1)//2
  mini=i*(i-1)//2
  ans+=maxi-mini+1
print(ans%mod)

Measured memory_bytes: 9144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 100005
#define pie 3.14159265358979323846264338
#define minuss 1e-6
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define BIG 100000000
#define N 10000
double tra[10000][3];
ll co[10000];
int main()
{

    double n;
    cin>>n;
    double sum=2*pie*n;
    std::cout << std::fixed;
    std::cout << std::setprecision(20);
    std::cout << sum<<endl;

}


Measured memory_bytes: 3784