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

#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define nl      '\n'

typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
    faster
	ll n,i,j,r,x;
	string s="abcdefghijklmnopqrstuvwxyz";
	string ans="";
	cin>>n;
	while(n)
	{
	    n--;
		ans=s[n%26]+ans;
		n/=26;
	}
	cout<<ans<<nl;
	return 0;
}


Measured memory_bytes: 3628
// Aizu Vol0 0006: Reverse Sequence
// 2017.7.28

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

char *gets(char *);

int main()
{
	char buf[1000], *p, *p0;

	gets(buf);
	p0 = buf;
	p = p0 + strlen(buf) - 1;
	while (p >= p0) putchar(*p--);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 524
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
int l=1,r;
int main(){
	int n,m;
	cin>>n>>m;
	r=n;
	for (int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		l=max(l,x);
		r=min(r,y);
	}
	cout<<max(0,r-l+1); 
}

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

struct Point2D {
    double x, y;

    Point2D() {}
    Point2D(double ax, double ay) {
        x = ax;
        y = ay;
    }
    Point2D operator -(Point2D &p) {
        return Point2D(x - p.x, y - p.y);
    }
    double cross(Point2D &p) { // only z
        return x * p.y - y * p.x;
    }
};

namespace std {
    istream &operator>>(istream &is, Point2D &p) {
        is >> p.x >> p.y;
        return is;
    }

    ostream &operator<<(ostream &os, Point2D &p) {
        os << fixed << p.x << " " << p.y;
        return os;
    }

    template <typename T>
    ostream &operator<<(ostream &os, vector<T> &v) {
        if (v.size()) {
            cout << v.front();
            for (auto vi = v.begin() + 1; vi != v.end(); vi++)
                cout << " " << *vi;
        }

        return os;
    }
}

template <typename T>
inline int sign(T x) { return (x > T(0)) - (x < T(0)); }

int main()
{
    vector<Point2D> triangle(3);
    Point2D p;

    for (; cin >> triangle[0] >> triangle[1] >> triangle[2] >> p;) {
        int acc = 0;
        for (int i = 0; i < 3; i++) {
            Point2D v = triangle[i] - triangle[(i + 1) % 3];
            Point2D pv = triangle[i] - p;

            acc += sign(v.cross(pv));
        }
        cout << ((abs(acc) == 3) ? "YES" : "NO") << endl;
    }

    return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;
int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    int q; cin >> q;
    rep(i,q){
        ll k;
        cin >> k;
        vector<ll>::iterator it = lower_bound(all(a), k);
        int ans = it - a.begin();
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
  int x;
  cin >> x;
 int a;
  if (x%2==0) {
    a=(x/2)*(x/2);
  }
  else{
    a=((x-1)/2)*((x+1)/2);
  }

  cout << a << endl;
}


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

int x,a,b;

int main(){
	cin >> x >> a >> b;

	if(abs(x-a)>abs(x-b)){
		cout << "B" << endl;
	}else if(abs(x-a)<abs(x-b)){
		cout << "A" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long int lnt;
typedef pair<lnt,lnt> P;
lnt k,t;
lnt c[10000];
int main()
{
	cin>>k>>t;
	lnt a=0;
	for(lnt i=0;i<t;i++) {
		cin>>c[i];
		a=max(a,c[i]);
	}
	lnt ans = a - (k-a) -1 ;
	printf("%lld\n",ans>0?ans:0);
} 

Measured memory_bytes: 256
list = [int(input()) for i in range(10)]
s=0
t=0
u=0
for i in range(10):
    if s<list[i]:
        u=t
        t=s
        s=list[i]
    elif t<list[i]:
        u=t
        t=list[i]
    elif u<list[i]:
        u=list[i]
print(s)
print(t)
print(u)


Measured memory_bytes: 5600
N, M, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)
A.sort()

sun = 0
cost = 0
for a, b in A:
    if sun + b <= M:
        sun += b
        cost += a*b
        if sun == M:
            print(cost)
            break
    else:
        cost += (M-sun)*a
        print(cost)
        break
    

Measured memory_bytes: 31600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define inf 2e18
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007
#define lop0(n) for(ll i=0;i<n;i++)
#define lopj(n) for(ll j=0;j<n;j++)
#define lop1(n) for(ll i=1;i<=n;i++)
#define all(v) v.begin(),v.end()
ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

main()
{
    ll n,cnt=0,f=0;
    cin>>n;
    while(n--)
    {
        ll a,b;
        cin>>a>>b;
        if(a==b)
        {
            cnt+=1;
            if(cnt>=3) f=1;
        }
        else cnt=0;
    }
    if(f) cout<<"Yes";
    else cout<<"No";
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
 
#define X first
#define Y second

const int MAXN = 110;

int n;
char s[MAXN];

pair<int, string> operator + (pair<int, string> a, pair<int, string> b)
{
	return make_pair(a.X+b.X, a.Y+b.Y);
}

int b[MAXN][MAXN];
pair<int, string> F[MAXN][MAXN];

int main()
{
	
	scanf("%d", &n);
	scanf("%s", s+1);
	
	for (int i = 1; i <= n; ++ i)
	{
		int cur = 0;
		for (int j = i; j <= n; ++ j)
		{
			if (s[j] == '(') cur ++;
			if (s[j] == ')') cur --;
			if (cur < 0) break;
			if (cur == 0) b[i][j] = 1;
		}
	}
	
	for (int k = 1; k <= n; ++ k)
		for (int i = 1; i <= n; ++ i)
		{
			int j = i+k-1;
			if (j > n) continue;
			string ss;
			for (int p = i; p <= j; ++ p)
				ss += s[p];
			F[i][j] = b[i][j] ? make_pair(j-i+1, ss) : make_pair(201, "");
			for (int p = i; p < j; ++ p)
				F[i][j] = min(F[i][j], F[i][p]+F[p+1][j]);
			if (s[j] == ')')
				F[i][j] = min(F[i][j], make_pair(1, "(")+F[i][j-1]+make_pair(1, ")"));
			if (s[i] == '(')
				F[i][j] = min(F[i][j], make_pair(1, "(")+F[i+1][j]+make_pair(1, ")"));
		}
	cout << F[1][n].Y << endl;
	
	return 0;
}


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

#define LL long long

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

int main()
{
	LL T, X;
	cin >> T >> X;

	cout << T / (double)X << endl;



	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stack>
#include<map>
#include<vector>
#include<utility>
#include<string>
using namespace std;
typedef long long ll;

ll h,w,n,a,b;
string s;
typedef pair<long long,long long> p;

int main(void)
{
  cin >> s;
  int a=-1,b=-1;
  int length=s.size();
  for(int i=0;i<length-1;i++)
    {
      if(s[i]==s[i+1])
	{
	  a=i+1;b=i+2;
	}
    }
  for(int i=0;i<length-2;i++)
    {
      if(s[i]==s[i+2])
	{
	  a=i+1;b=i+3;
	}
    }
  cout << a << ' ' << b << endl;
  return 0;
  
}

Measured memory_bytes: 512
// Choose Integers
#include <cmath>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int s = -1;
    bool can = A % B == C;
    for (int i = 1; (A * i) % B != s; i++) {
        if (i == 1) {
            s = A % B;
            continue;
        }
        if ((A * i) % B == C) can = true;
    }
    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
import collections

def c2c(n):
    return n*(n-1)//2

N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
c_l = list(c.values())
d2 = sum([c2c(i) for i in c_l])
#print(d2)

for i in range(len(A)):
    print(d2-(c[A[i]]-1))

Measured memory_bytes: 26780
#include<stdio.h>
int a[200001],b[200001],g[200001],p[200001];
int main()
{	int n,m,i,x,y,j,s=0;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
	{scanf("%d%d",&a[i],&b[i]);
	}
	for(i=1;i<=m;i++)
	{
		if(b[i]==n)
		{
		p[a[i]]++;
		}
		if(a[i]==1)
		{
			g[b[i]]++;
		}
	}
	for(i=0;i<=n;i++)
	{
			if(p[i]!=0&&g[i]!=0)
			s=1;
	}
	if(s==1)
	printf("POSSIBLE\n");
	else
	printf("IMPOSSIBLE\n");
}

Measured memory_bytes: 3328
import java.util.*;

class Main {
    public static void main(String[] args) {
	double r;
	Scanner sc = new Scanner(System.in);
	r = sc.nextDouble();

	double menseki = r * r * Math.PI;
	double shu = 2 * r * Math.PI;

	System.out.printf("%.6f %.6f\n", menseki, shu);
    }
}

Measured memory_bytes: 19064
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

/*
5個の数が素数であれそれらの数の5で割ったあまりが全部一緒なら
和は5の倍数である
 */
ll maxNum=55560;
vector<bool> isPrime(maxNum,true);
void sieve(ll n){
    isPrime[0]=false;
    isPrime[1]=false;

    for(ll i=2;i<n;i++){
        if(!isPrime[i]) continue;
        for(int j=i*2;j<=n;j+=i)    isPrime[j]=false;
    }
}

int main(){
    sieve(55556);
    vector<ll> ans;
    for(ll i=2;i<55555;i++){
        if(isPrime[i]&&(i%5==2)) ans.push_back(i);
    }
    ll n;
    cin>>n;
    rep(i,n-1){
        cout<<ans[i]<<' ';
    }
    cout<<ans[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cctype>
#include <vector>
#include <string>
using namespace std; 
char easytolower(char in){
        if(in<='Z' && in>='A') return in-('Z'-'z');
        return in;
}
int main() {
    vector<char> al;
    char a;
    for(a = 'a';a<='z';a++) al.push_back(a);
    string read;
    int i,count[26];
    for(auto& c: count) c = 0;
    while(getline(cin, read)){
        transform(read.begin(),read.end(),read.begin(),easytolower);
        for(i=0;i<al.size();i++){
            for(auto r: read){
                if(r == al[i]) count[i]++;
            }
        }
    }
    for(i=0;i<al.size();i++){
        cout << al[i] << " : " << count[i] << endl;
    }
    return 0;

}


Measured memory_bytes: 3196
#include<iostream>
#include<string>

using namespace std;

int main(){
    int n, T_pt = 0, H_pt = 0;
    string TARO, HANAKO;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> TARO >> HANAKO;
        if(TARO == HANAKO){
             T_pt++;
             H_pt++;
        }else if(TARO < HANAKO){
            H_pt += 3;
        }else if(TARO > HANAKO){
            T_pt += 3;
        }
    }
    cout << T_pt << " " << H_pt << endl;
    return 0;
}


Measured memory_bytes: 3144
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1e18 + 10;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }

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

int main(){
    int H, W; cin >> H >> W;
    vector<string> grid(H);
    rep(i, H) cin >> grid[i];

    ll res = 0;
    vector<vector<int>> d(H, vector<int>(W, INF)); 
    rep(i, H){
        rep(j, W){
            //BFS 始点が白の場合のみ探索する
            if(grid[i][j]=='#' or d[i][j] != INF)continue;
            queue<pii> que; que.push({i, j});
            d[i][j] = 0;
            ll white = 1, black = 0;
            while(!que.empty()){
                auto p = que.front(); que.pop();
                int vh = p.first, vw = p.second;
                rep(k, 4){
                    int ny = vh + dy[k], nx = vw + dx[k];
                    int cost = d[vh][vw] + 1;
                    if(ny<0 or nx<0 or ny>=H or nx>=W)continue;
                    if(d[ny][nx] != INF)continue;
                    if(grid[ny][nx]=='.' and cost%2==0 or grid[ny][nx]=='#' and cost%2==1){
                        d[ny][nx] = cost;
                        que.push({ny, nx});
                        grid[ny][nx] == '#' ? black++ : white++;                                     
                    }   
                }
            }
            res += white * black;   
        }
    }
    cout << res << ln;
}


Measured memory_bytes: 4460
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    String b=sc.next();
    int c=sc.nextInt();
    if(b.equals("+")) System.out.println(a+c);
    else System.out.println(a-c);
  }
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

long long powmod(long long a,long long b){
    long long c=1;
    while(b>0){
        if(b&1) c=a*c%mod;
        a=a*a%mod;
        b>>=1;
    }
    return c;
}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,x,ans=0;
	cin >> n >> x;
	vll a(n);
	rep(i,n) cin >> a[i];
	sort(all(a));
	rep(i,n){
		x-=a[i];
		ans++;
		if(x<1) break;
	}
	cout << (x==0?ans:ans-1) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		String x=scan.next();
		char[] y=x.toCharArray();
		if(y[0]>='A' && y[0]<='Z') {
			System.out.println("A");
		}
		else {
			System.out.println("a");
		}
	}

}


Measured memory_bytes: 35380
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int H,W;
    string a[101];
    int ans[101][101]={0};
    cin>>H>>W;
    for(int i=0;i<H;i++)cin>>a[i];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int k=0;;k++){
                if(j-k==-1){
                    ans[i][j]=-1;
                    break;
                }
                if(a[i][j-k]=='c'){
                    ans[i][j]=k;
                    break;
                }
            }
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(j!=0)printf(" ");
            cout<<ans[i][j];
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 1276
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

M=10**6+10
n=int(input())
a=Counter(lmp()).most_common()
a=sorted(a, key=lambda x: x[0])
c=[0]*M
for j,x in a:
    if c[j]==0:
        k=2
        while j*k<M:
            c[j*k]=1
            k+=1
ans=0
for x,y in a:
    if c[x]==0 and y==1:
        ans+=1
print(ans)

Measured memory_bytes: 43880
n = int(input())
sum=0
dig = len(list(str(n)))
# print(dig)
for i in range(1,dig+1):
    if i%2==1:
        if i==dig:
            sum+=(n-10**(i-1)+1)
        else:
            sum+=10**(i-1)*9

print(sum)

Measured memory_bytes: 3060
import scala.io.StdIn.readLine

object Main extends App {
  val Array(n, k) = readLine.split(" ").map(_.toInt)
  var ans = 0.0

  for (i <- 1 to n) {
    var initialScore = i
    var count = 0

    while (initialScore < k) {
      initialScore = initialScore * 2
      count += 1
    }

    ans += 1 / (math.pow(2, count) * n)
  }

  println(ans)
}


Measured memory_bytes: 25400
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,int> P2;
typedef pair<pair<ll,ll>,int> T;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 20000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int M,N,K;
struct edge
{
	int to;
	ll cost;
	edge(int to,ll cost):to(to),cost(cost){}
};
vector<edge> G[400100];
ll x[200100],y[200100];
ll d[400100];
int s=-1,t=-1,room;
vector<T> xy,yx;
void add_edge(int from,int to,ll cost)
{
	G[from].pb(edge(to,cost));
	G[to].pb(edge(from,cost));
	return;
}
void dijkstra(int S)
{
	for(int i=0;i<400100;i++)d[i]=INF;
	d[S]=0;
	priority_queue<P2,vector<P2>,greater<P2> > q;
	q.push(P2(0ll,S));
	while(!q.empty())
	{
		P2 a=q.top();
		q.pop();
		int v=a.sec;
		if(d[v]<a.fi)continue;
		for(int i=0;i<G[v].size();i++)
		{
			edge e=G[v][i];
			if(d[e.to]>d[v]+e.cost)
			{
				d[e.to]=d[v]+e.cost;
				q.push(P2(d[e.to],e.to));
			}
		}
	}
	return;
}
int main()
{
	scanf("%d %d %d",&M,&N,&K);
	room=K;
	for(int i=0;i<K;i++)
	{
		scanf("%lld %lld",&x[i],&y[i]);
		if(x[i]==1&&y[i]==1)s=i;
		if(x[i]==M&&y[i]==N)t=i;
	}
	if(s==-1)
	{
		s=room;
		x[room]=1;y[room]=1;
		room++;
	}
	if(t==-1)
	{
		t=room;
		x[room]=M;y[room]=N;
		room++;
	}
	for(int i=0;i<K;i++)add_edge(i,i+room,1ll);
	for(int i=0;i<room;i++)
	{
		xy.pb(T(P(x[i],y[i]),i));
		yx.pb(T(P(y[i],x[i]),i));
	}
	SORT(xy);
	SORT(yx);
	for(int i=1;i<room;i++)
	{
		if(xy[i-1].fi.fi==xy[i].fi.fi)add_edge(xy[i-1].sec,xy[i].sec,xy[i].fi.sec-xy[i-1].fi.sec);
		if(yx[i-1].fi.fi==yx[i].fi.fi)add_edge(yx[i-1].sec+room,yx[i].sec+room,yx[i].fi.sec-yx[i-1].fi.sec);
	}
	dijkstra(s);
	if(d[t]==INF&&d[t+room]==INF)
	{
		printf("-1\n");
		return 0;
	}
	printf("%lld\n",min(d[t],d[t+room]));
	return 0;
}

Measured memory_bytes: 62348
#include <iostream>
using namespace std;
int main(){
	long long  n, m, ans;
	cin >> n >> m;
	if(m % 2 == 1){
		ans = (n / m) * (n / m) * (n / m);
	}
    else{
		long long  a = n / m;
		long long  b = n / (m / 2) - a;
		ans = (b * b * b + a * a * a);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
n , t = map(int,input().split())
z = list(map(int,input().split()))
ans = 0
for i in range(1,n):
    if z[i-1] + t <= z[i]:
        ans += t
    elif z[i-1] + t > z[i]:
        ans += z[i] - z[i-1]
        
ans += t

print(ans)

Measured memory_bytes: 25200
#include <algorithm>
#include <iostream>
#include <string>

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

	int bw = 0;
	for(int i = 0; i < S.size(); i++) {
		const bool isEven = i % 2 == 0;
		const bool isBlack = S[i] == '0';
		if(isEven && !isBlack || !isEven && isBlack) {
			bw++;
		}
	}

	const int wb = S.size() - bw;
	const int result = std::min(bw, wb);

	std::cout << result << std::endl;

	return 0;
}


Measured memory_bytes: 512
using System;
    class ProgramB
    {
        static void Main(string[] args)
        {
            String[] input = (Console.ReadLine()).Split(" ");
            int count = int.Parse(input[0]);
            int distance = int.Parse(input[1]);

            int ans = 0;

            for(int i=0; i<count; i++)
            {
                String[] zahyo = (Console.ReadLine()).Split(" ");
                int zahyo_x = int.Parse(zahyo[0]);
                int zahyo_y = int.Parse(zahyo[1]);

                double zahyo_distance = Math.Sqrt(Math.Pow(zahyo_x, 2) + Math.Pow(zahyo_y, 2));
                if(zahyo_distance<=distance)
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }

Measured memory_bytes: 40708
sx, sy, tx, ty = map(int, input().split())
dx = tx - sx
dy = ty - sy
if dx >= 0:
	if dy >= 0:
		ans = "U"*dy + "R"*dx + "D"*dy + "L"*(dx+1) + "U"*(dy+1) + "R"*(dx+1) + "D" + "R" + "D"*(dy+1) + "L"*(dx+1) + "U"
	else:
		ans = "D"*dy + "R"*dx + "U"*dy + "L"*(dx+1) + "D"*(dy+1) + "R"*(dx+1) + "U" + "R" + "U"*(dy+1) + "L"*(dx+1) + "D"
else:
	if dy >= 0:
		ans = "U"*dy + "L"*dx + "D"*dy + "R"*(dx+1) + "U"*(dy+1) + "L"*(dx+1) + "D" + "L" + "D"*(dy+1) + "R"*(dx+1) + "U"
	else:
		ans = "D"*dy + "L"*dx + "U"*dy + "R"*(dx+1) + "D"*(dy+1) + "L"*(dx+1) + "U" + "L" + "U"*(dy+1) + "R"*(dx+1) + "D"
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        String A = scan.next();
        String B = scan.next();
        String C = scan.next();
        
        if(A.charAt(A.length() - 1) == B.charAt(0)) {
            if(B.charAt(B.length() - 1) == C.charAt(0)) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}


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

struct Card { char suit, value; };

void bubble(struct Card A[], int N) {
        for ( int i = 0; i< N; i++ ) {
                for ( int j = N -1 ; j >= i + 1; j-- ) {
                        if ( A[j].value < A[j-1].value){
                                Card t = A[j]; A[j] = A[j-1]; A[j-1] = t; //std::swapがつかえない
                        }
                }
        }
}

void selection(struct Card A[], int N) {
        for ( int i = 0; i < N; i++ ) {
                int minj = i;
                for ( int j = i; j < N; j++ ) {
                        if ( A[j].value < A[minj].value ) minj = j;
                }
                Card t = A[i]; A[i] = A[minj]; A[minj] = t;
        }
}

void print (struct Card A[], int N){
        for ( int i = 0; i < N; i++) {
                if ( i > 0) cout << " ";
                cout << A[i].suit << A[i].value;
        }
        cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
        for ( int i = 0; i < N; i++ ) {
                if ( C1[i].suit != C2[i].suit ) return false;
        }
        return true;
}

int main () {
        Card C1[100], C2[100];
        int N;
        char ch;

        cin >> N;
        for ( int i = 0; i < N; i++ ) {
                cin >> C1[i].suit >> C1[i].value;
        }

        for ( int i = 0; i < N; i++ ) C2[i] = C1[i];

        bubble(C1,N);
        selection(C2,N);

        print(C1,N);
        cout << "Stable" << endl;
        print(C2, N);
        if ( isStable(C1,C2,N)) {
                cout << "Stable" << endl;
        } else {
                cout << "Not stable" << endl;
        }
        return 0;
}



Measured memory_bytes: 3084
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


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-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9 + 7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;


int D[1000010], M[1000010];
void solve() {
	int N;
	string S;
	int Q; cin >> N >> S >> Q;
	REP(i, N) {
		D[i + 1] += D[i];
		M[i + 1] += M[i];
		if (S[i] == 'D')D[i + 1]++;
		if (S[i] == 'M')M[i + 1]++;
	}
	while (Q--) {
		int K; cin >> K;
		int res = 0;
		int ans = 0;
		REP(r, N) {
			if (r >= K&&S[r-K]=='D') {
				res -= (M[r] - M[r - K]);
			}
			if (S[r] == 'C')ans += res;
			if (S[r] == 'M') {
				res += (D[r] - D[max(0LL, r - K+1)]);
			}
		}
		print(ans);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 17052
#include <stdio.h>

int main(){
  int r,g,b,n;
  scanf("%d%d%d%d",&r,&g,&b,&n);
  int answer = 0;
  int bin;
  for(int i = 0; i <= n/r; ++i){
    for(int j = 0; j <= n/g; ++j){
      bin = n - i*r - j*g;
      if(bin < 0) break;
      if((bin % b) == 0) answer++;
    }
  }
  
  printf("%d\n",answer);
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" <<endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main()
{
    double ans = 0;
    int n;
    cin >> n;
    REP(i, n) {
        double t;
        cin >> t;
        ans += 1/t;
    }

    cout << setprecision(12) << 1/ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#pragma comment(linker, "/STACK: 20000000005")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

const ll N = 1e12, MOD = 1e9 + 7;

int a[3];


main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    for (int i = 0; i < 3; i++)
        cin >> a[i];
    sort (a, a + 3);
    cout << a[0] + a[1] << endl;
    return 0;
}


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

const int N=2010;
int n,m;
bitset<N>M[N],sub_tree[N],chain[N][N],res;
vector<int>g[N];
queue<pair<int,int> >q;
int now;
void dfs(int x,int fa=-1){
	sub_tree[x].reset();sub_tree[x][x]=chain[now][x][x]=1;
	for(int i:g[x])if(i!=fa){chain[now][i]=chain[now][x];dfs(i,x);sub_tree[x]|=sub_tree[i];}
	chain[now][x]|=sub_tree[x];
}

void add_edge(int x,int y){M[x][y]=M[y][x]=1;q.emplace(x,y);}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<n;++i){
		int x,y;cin>>x>>y;
		g[x].push_back(y);g[y].push_back(x);
	}
	for(int i=1;i<=n;++i){now=i;dfs(i);}
	for(int i=1;i<=n;++i)for(int j=i+1;j<=n;++j)
		chain[i][j]=chain[j][i]=(chain[i][j]|chain[j][i]);
	for(int i=1;i<=m;++i){
		int x,y;cin>>x>>y;
		add_edge(x,y);
	}
	for(int i=1;i<=n;++i)M[i][i]=1;
	int ans=0;
	while(!q.empty()){
		auto x=q.front();q.pop();++ans;
		res=(M[x.first]^M[x.second])&chain[x.first][x.second];
		for(int it=res._Find_first();it!=res.size();it=res._Find_next(it))if(M[x.first][it])add_edge(x.second,it);else add_edge(x.first,it);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1022900
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut v = read_vec::<i64>();
    v.sort();
    v.reverse();
    let mut alice = 0;
    let mut bob = 0;
    for i in 0..n {
        if i % 2 == 0 {
            alice += v[i];
        } else {
            bob += v[i];
        }
    }
    let ans = alice - bob;
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        Map<Integer, Integer> primeFactors = new HashMap<>();
        for (int i = 2; i * i <= m; i++) {
            while (m % i == 0) {
                m /= i;
                primeFactors.put(i, primeFactors.getOrDefault(i, 0) + 1);
            }
        }
        if (!primeFactors.isEmpty() && m != 1) {
            primeFactors.put(m, primeFactors.getOrDefault(m, 0) + 1);
        }

        long ans = 1;
        for (int i : primeFactors.values()) {
            ans = ans * combinationAndMod(i + n - 1, i) % 1000000007;
        }
        System.out.println(ans);
    }

    static long combinationAndMod(long n, long r) {
        r = Math.min(r, n - r);
        long x = 1, y = 1;
        for (long i = 1; i <= r; i++) {
            x = x * (n - r + i) % 1000000007;
            y = y * i % 1000000007;
        }
        return x * powAndMod(y, 1000000005) % 1000000007;
    }

    static long powAndMod(long a, long b) {
        if (b == 0)
            return 1;
        if ((b & 1) == 1)
            return a * powAndMod(a, b - 1) % 1000000007;
        return powAndMod(a * a % 1000000007, b / 2);
    }
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		if(N%2==0) {
			System.out.println(N);
		}else {
			System.out.println(N*2);
		}
	}
}

Measured memory_bytes: 23380
#include<stdio.h>
int main(void) {

	int i, j, k, n, x[100], y[100], X = 0, Y = 0;
	long long int  tmp, height, h[100];

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d %d %lld", &x[i], &y[i], &h[i]);
	}

	for (i = 0; i <= 100; i++) {
		for (j = 0; j <= 100; j++) {

			height = -2;

			for (k = 0; k < n; k++) {
				if (i - x[k] < 0)X = -(i - x[k]);
				else X = i - x[k];
				if (j - y[k] < 0)Y = -(j - y[k]);
				else Y = j - y[k];
				if (h[k] > 0) {
					tmp = h[k] + X + Y;
					if (height == -2)height = tmp;
					else if (height != tmp) {
						height = -1;
						break;
					}
				}
			}

			if (height == -1)continue;

			for (k = 0; k < n; k++) {
				if (i - x[k] < 0)X = -(i - x[k]);
				else X = i - x[k];
				if (j - y[k] < 0)Y = -(j - y[k]);
				else Y = j - y[k];
				if (h[k] == 0) {
					if (height > X + Y) {
						height = -1;
						break;
					}
				}
			}
			if (height == -1)continue;

			printf("%d %d %lld\n", i, j, height);
			return 0;
		}
	}

}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
string s="";
int main()
{
	l n;
	cin>>n;
	while(n>=1)
	{
		n--;
		l p=n%26;
		s+=(p+'a');
		n=n/26;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define PB push_back
#define MP make_pair
#define ll long long
#define ull unsigned long long 
#define pii pair<int,int>
#define all(X) (X).begin(),(X).end()
#define F first
#define S second
#define endl cout<<'\n';
#define __IO ios::sync_with_stdio(false),cin.tie(0);
using namespace std;
int dp[100005] , s[100005];
int main(){
__IO
	int n;
	cin >> n;
	for(int i=0 ; i<n ; ++i) cin >> s[i];
	dp[0] = 0 , dp[1] = abs(s[1] - s[0]);
	for(int i=2 ; i<n ; ++i)
		dp[i] = min(dp[i-2] + abs(s[i-2] - s[i]) , dp[i-1] + abs(s[i-1] - s[i]));
	cout << dp[n-1] <<'\n';
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[] array;
	
	static void read(){
		array = new int[10];
		for(int i = 0; i < 10; i++){
			array[i] = sc.nextInt();
		}
	}

	static void solve(){
		Arrays.sort(array);
		System.out.println(array[9]);
		System.out.println(array[8]);
		System.out.println(array[7]);
	}
	public static void main(String[] args) {
		read();
		solve();
	}
}

Measured memory_bytes: 17180
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        string s;
        map<string, int> mp;
        int mx=0;
        for(int i=0; i<n; ++i){
            cin>>s;
            ++mp[s];
            mx=max(mx, mp[s]);
        }
        set<string> st;
        for(auto it:mp){
        	if(it.sc==mx){
        		st.insert(it.fs);
        	}
        }
        for(auto it:st){
        	cout<<it<<endl;
        }
    }
  return 0;
}




Measured memory_bytes: 34560
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
const int max_n = 5e4+1;
long long cnt[111];
long long m,n,a=0,b;
const int INF = 1e8;
const int mod = 1e9 + 7;
long dist[max_n],s[max_n];
long long dp[max_n];
vector<vector<int> > G;
bool isprime(long long xx){
    if(xx == 2) return true;
    if(xx % 2==0 || xx<2)    return false;
    long long ii = 3;
    while(ii*ii <= xx){
        if(xx %ii == 0) return false;
        ii += 2;
    }
    return true;
}
long long gcd(long long xx, long long yy){
    if(yy == 0) return xx;
    long long k = xx/yy;
    long long c = xx - k*yy;
    return gcd(yy, c);
}
void solve(){
    dp[0] = 0;
    for(int i=1 ; i<=n ; i++){
        for(int j=0 ; j<m ; j++){
            if(i >= s[j])   dp[i] = min(dp[i], dp[i-s[j]]+1);
        }
    }
    cout << dp[n] << endl;
}
int main(){
    cin >> n >> m;
    for(int i=0 ; i<m ; i++){
        cin >> s[i];
    }
    fill(dp, dp+n+1, INF);
    solve();
    return 0;
}


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


long long int Exp(long long int exp_n,long long int exp_e, long long exp_mod);


int main(){
  int N,W=0,R=0,O=0;
  cin >> N;
  char C[N];
  for(int i=0;i<N;i++){
    cin >> C[i];
    if(C[i]=='R'){
      R++;
    }else{
      W++;
    }
  }
  for(int i=0;i<R;i++){
    if(C[i]=='W'){
      O++;
    }
  }
  
  cout << O;
  
  return 0;
}


long long int Exp(long long int exp_n,long long int exp_e, long long int exp_mod){
  long long int exp_o = 1;
  long long int exp_x=exp_n;
  long long int exp_tmp;
  
  while(0<exp_e){
    exp_tmp = exp_e/2;
    if(exp_e - exp_tmp*2 == 1){
      exp_o = exp_o*exp_x;
      if(exp_o>exp_mod){
        exp_o=exp_o%exp_mod;
      }
    }
    
    exp_x = exp_x*exp_x;
    if(exp_x>exp_mod){
      exp_x=exp_x%exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


Measured memory_bytes: 3728
import java.util.*;
class cake {
	public long x,y,z;
}
public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		System.out.println(a * b - a - b + 1);
	}
}


Measured memory_bytes: 21844
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    int64_t result = 1;
    int n;
    cin >> n;
    for (int64_t i = 1; i <= n; i++) {
        result *= i;
        result %= 1000000007;
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
cnt = [0] * n
chk = [0] * n
ans = 0

for i in range(m):
    a,b = map(int, input().split())
    if h[a-1] > h[b-1]:
        cnt[a-1] += 1
    if h[a-1] < h[b-1]:
        cnt[b-1] += 1
    chk[a-1] += 1
    chk[b-1] += 1

for i in range(n):
    if cnt[i] == chk[i]:
        ans += 1

print(ans)

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



int main() {
    char n[11];
    cin >> n;
    long long ans = 0;
    vector<int> S;


    for(int bit = 0;bit < (1<<strlen(n)-1);++bit)
    {


        long long a = n[0] - '0';
        for(int i = 0;i < strlen(n)-1;++i){
            
            if(bit & (1<<i)){
                ans += a;
                a = n[i+1] - '0';
            }else{
                a = a*10 + (n[i+1] - '0');
            }
        }
        ans += a;


    }
    cout << ans << endl;
    


}

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

int main(){
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    for(int64_t i=0;i<N;i++){
        cin >> A.at(i);
    }

    int64_t count = 0;
    int64_t pre = A.at(0);
    int64_t post;
    for(int64_t i=0;i<N;i++){
        post = A.at(i);
        if(pre > post){
            count += (pre - post);
        }else if(pre < post){
            pre = post;
        }
    }

    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 4776
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t,x,y,m,q;
 
int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n;
      ll a[n],b[n];
      for(int i=0;i<n;i++){
        cin>>x>>y;
        a[i]=x+y;
        b[i]=x-y;
      }
      sort(a,a+n);
      sort(b,b+n);
      cout<<max(a[n-1]-a[0],b[n-1]-b[0]);
}

Measured memory_bytes: 6680
import Data.Foldable (traverse_)
import Data.Functor ((<$>))

main = do
  xs <- takeWhile (\[x, y] -> [x, y] /= [0, 0]) . map (map read . words) . lines <$> getContents
  traverse_ printBox xs
  where
  printBox [x, y] = putStrLn $ unlines $ replicate x (replicate y '#')



Measured memory_bytes: 4528
function Main(input){
	var n = input;
	var a = Math.floor(n / 100);
	var b = n % 10; 
	if(a == b){
		console.log("Yes");
	}else{
		console.log("No");
	}	
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  int n; cin >> n;
  vector<ll> dp(1000010);
  dp[1] = 1;

  for(int i = 2; i < n; i++){
    for(int j = 1; j*j <= i; j++){
      if(i%j == 0){
        if(j*j == i) dp.at(i)++;
        else dp.at(i) += 2;
      }
    }
    dp.at(i) += dp[i-1];
    //cout << dp[i] << endl;
  }

  cout << dp[n-1] << endl;
}


Measured memory_bytes: 11172
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#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 MAX 1e16
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b,ll m){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a) % m;  a = (a * a) % m;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 2e3 + 3;
ll i,n,m,g,j,ans;
char a[N][N];
ll l[N][N], r[N][N], u[N][N], d[N][N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>m;
    rep(i,1,n + 1) rep(j,1,m + 1) cin>>a[i][j];
    rep(i,1,n + 1){
        l[i][0] = 0;
        rep(j,1,m + 1){
            l[i][j] = l[i][j - 1];
            if(a[i][j] == '#')
                l[i][j] = j;
        }
        r[i][m + 1] = m + 1;
        revrep(j,m,1){
            r[i][j] = r[i][j + 1];
            if(a[i][j] == '#')
                r[i][j] = j;
        }
    }
    rep(j,1,m + 1){
        u[0][j] = 0;
        rep(i,1,n + 1){
            u[i][j] = u[i - 1][j];
            if(a[i][j] == '#')
                u[i][j] = i;
        }
        d[n + 1][j] = n + 1;
        revrep(i,n,1){
            d[i][j] = d[i + 1][j];
            if(a[i][j] == '#')
                d[i][j] = i;
        }
    }
    rep(i,1,n + 1) rep(j,1,m + 1) if(a[i][j] != '#'){
         g = r[i][j] - l[i][j];
         g += d[i][j] - u[i][j];
         ans = max(ans, g - 3);
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 129536
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define Init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  Init();
  ll N, H;
  cin >> N >> H;

  vector<P> katana(N);
  ll katana_m = 0;
  rep(i, N) {
    ll a, b;
    cin >> a >> b;
    katana[i] = {b, a};
    if (a > katana_m) {
      katana_m = a;
    }
  }

  SORT(katana);

  ll ans = 0;
  repr(i, N - 1) {
    if (katana[i].first > katana_m) {
      ans++;
      H -= katana[i].first;
    }
    if (H <= 0) {
      COUT(ans);
      return 0;
    }
  }

  if (H % katana_m == 0) {
    ans += H / katana_m;
  } else {
    ans += H / katana_m + 1;
  }

  COUT(ans);
  return 0;
}

Measured memory_bytes: 1792