akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

int main() {
	int r, c, n;
	cin >> r >> c >> n;
	int x1, y1, x2, y2;
	stack<int> st;
	vector<pair<int, int>> res[4];
	for (int i = 1; i <= n; i++) {
		cin >> x1 >> y1 >> x2 >> y2;
		if ((x1 == 0 || y1 == 0 || x1 == r || y1 == c) && (x2 == 0 || y2 == 0 || x2 == r || y2 == c)) {
			if (x1 == 0) {
				res[0].emplace_back(make_pair(y1, i));
			}
			else if (y1 == c) {
				res[1].emplace_back(make_pair(x1, i));
			}
			else if (x1 == r) {
				res[2].emplace_back(make_pair(-y1, i));
			}
			else {
				res[3].emplace_back(make_pair(-x1, i));
			}

			if (x2 == 0) {
				res[0].emplace_back(make_pair(y2, i));
			}
			else if (y2 == c) {
				res[1].emplace_back(make_pair(x2, i));
			}
			else if (x2 == r) {
				res[2].emplace_back(make_pair(-y2, i));
			}
			else {
				res[3].emplace_back(make_pair(-x2, i));
			}
		}
	}
	for (int i = 0; i < 4; i++) {
		sort(res[i].begin(), res[i].end());
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < res[i].size(); j++) {
			int id = res[i][j].second;
			if (st.size() && st.top() == id) {
				st.pop();
			}
			else {
				st.push(id);
			}
		}
	}
	cout << (st.size() ? "NO" : "YES") << endl;
}

Measured memory_bytes: 2520
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for (auto& e : a) cin >> e;
    
    long long ans = 0;
    for (int i = 0; i < n-1; i++) {
        long long d = max(0LL, a[i] + a[i+1] - k);
        ans += d;
        a[i+1] = max(0LL, a[i+1] - d);
    }
    
    cout << ans << endl;
    return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int S,W; cin >> S >> W;
    if(S<=W) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3632
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s.by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

pub fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let n: u32 = read(&mut stdin).unwrap();
    let mut cards: Vec<u32> = (0..n).map(|_x| read(&mut stdin).unwrap()).collect();

    cards.sort_by(|a, b| b.cmp(a));

    let alice = cards
        .iter()
        .enumerate()
        .filter(|x| x.0 % 2 == 0)
        .fold(0, |acc, x| acc + x.1);
    let bob = cards
        .iter()
        .enumerate()
        .filter(|x| x.0 % 2 != 0)
        .fold(0, |acc, x| acc + x.1);

    println!("{:?}", alice - bob);
}


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

bool f[10];

int n, k;

static bool ok(int x) {
	do {
		if (f[x % 10])
			return false;
		x/= 10; }
	while (x > 0);

	return true; }

int main() {
#ifdef HOME
	freopen("atc.in", "r", stdin);
	freopen("atc.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int t;

	cin >> n >> k;
	for (int i = 0; i < k; ++i) {
		cin >> t;
		f[t] = 1; }

	while (!ok(n))
		n+= 1;

	cout << n << endl;

	return 0; }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<set>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

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

multiset<long long> d;
rep(i,N){
   long long l;
    cin>>l;
    d.insert(l);
}

int M;
cin>>M;
vector<long long> t(M);
rep(i,M)cin>>t[i];

string ans="YES";
rep(i,M){
    auto it=d.find(t[i]);
    if(it==d.end()){
        ans="NO";
        break;
    }
    d.erase(it);
}
cout<<ans<<endl;
 return 0;
}
/*
5
3 1 4 1 5
3
5 4 3

YES


7
100 200 500 700 1200 1600 2000
6
100 200 500 700 1600 1600

NO

1
800
5
100 100 100 100 100

NO

15
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
9
5 4 3 2 1 2 3 4 5

YES
*/

Measured memory_bytes: 11136
D=int(input())
clist=list(map(int,input().split()))
smat=[[int(x) for x in input().split()] for _ in range(D)]
#print(clist)
#print(smat)

index_set=set(range(26))
for d in range(D):
  max_index=-1
  max_sd=-1
  for i in index_set:
    if max_sd<smat[d][i]:
      max_index=i
      max_sd=smat[d][i]
      
  max_index2=-1
  max_sd2=-1
  for i in range(26):
    if max_sd2<smat[d][i]:
      max_index2=i
      max_sd2=smat[d][i]
      
  if max_index==max_index2:
    print(max_index+1)
    index_set.remove(max_index)
  else:
    if max_sd2>4*max_sd:
      print(max_index2+1)
    else:
      print(max_index+1)
      index_set.remove(max_index)      
      
  if not index_set:
    index_set=set(range(26))
  else:
    max_c=0
    for i in index_set:
      max_c=max(max_c,clist[i])
    if max_c<10:
      index_set=set(range(26))

Measured memory_bytes: 69344
// abc142_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int n;
  cin >> n;
  cout << shosu(8);
  if (n%2==0) {
    cout << (double)(n/2)/n << endl;
  } else {
    cout << (double)((n+1)/2)/n << endl;
  }

  return 0;
}


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

#define rep(i,n) for(int i = 0;i<n;i++)
#define cint(a) int a; cin >> a;
#define cstr(str) string str; cin >> str;
#define vv(Type, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, r; cin >> n >> r;

	if (n >= 10) cout << r << endl;
	else cout << r + 100 * (10 - n) << endl;


	return 0;
}


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

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

  int y=0,ans=0;
  for(int i=1; i<1000000000; i++){
    y+=i;
    if(y>=x){
      ans=i;
      break;
    }
  }

  cout<<ans<<endl;
}

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

#define INF 1234567890
#define ll long long

ll res;
int N, Q;
bool dieY[200201], dieX[200201]; // 행, 열
map<int, int> D, R; // D[x] = y, R[y] = x

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> Q;
	res = (ll)(N-2)*(N-2);
	D[N] = N;
	R[N] = N;
	while(Q--)
	{
		int t, x;
		cin >> t >> x;
		if (t == 1) // 수직 뒤집기
		{
			if (dieX[x]) continue;
			dieX[x] = true;
			int d = D.lower_bound(x)->second;
			res -= d-2;
			// [2,d] 구간에서 x보다 큰 값들을 다 x로 바꾸기.
			if (x < R.begin()->second)
			{
				for(auto it = R.begin(); it != R.end(); )
				{
					if (it->first < d) it = R.erase(it);
					else break;
				}
				R[d] = x;
			}
		}
		else // 수평 뒤집기
		{
			int y = x;
			if (dieY[y]) continue;
			dieY[y] = true;
			int r = R.lower_bound(y)->second;
			res -= r-2;
			if (y < D.begin()->second)
			{
				for(auto it = D.begin(); it != D.end(); )
				{
					if (it->first < r) it = D.erase(it);
					else break;
				}
				D[r] = y;
			}
		}
		//printf("%dth step : %lld\n", tc, res);
	}
	cout << res;
	return 0;
}

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

int main() {
  int A[100][100], B[100][100], n, m, l, i, j, k;
  long c;

  cin >> n >> m >> l;

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      cin >> B[i][j];
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      c = 0;

      for (k = 0; k < m; k++) {
        c += A[i][k] * B[k][j];
      }

      cout << c;

      if (j != l - 1) {
        cout << ' ';
      }
    }

    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1236
# Aizu Problem 0107: Carry a Cheese
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    a, b, c = sorted([int(_) for _ in input().split()])
    R = .5 * math.sqrt(a**2 + b**2)
    if a == b == c == 0:
        break
    N = int(input())
    for _ in range(N):
        r = int(input())
        print("OK" if r > R else "NA")
        

Measured memory_bytes: 7752
N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
  a = int(input())
  for j in range(a):
    A[i].append(tuple(map(int,input().split())))
#print(A)

ans = 0
for i in range(1<<N):
  B = [0 for _ in range(N)]
  for j in range(N):
    if (i>>j)&1 == 1:
      B[j] = 1
  #print(B)
  flag = True
  for j in range(N):
    if B[j] == 1:
      for x,y in A[j]:
        if (y == 1 and B[x-1] == 0) or (y == 0 and B[x-1] == 1):
          flag = False
          break
    if not flag:
      break
  if flag:
    ans = max(sum(B),ans)
print(ans)


Measured memory_bytes: 49516
N = int(input())
cnt = [[0] * 10 for i in range(10)]
for n in range(1, N + 1):
    cnt[int(str(n)[0])][int(str(n)[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)

Measured memory_bytes: 9136
using System;

namespace abc104_b
{
	class Program
	{
		static void Main(string[] args)
		{
			string s = Console.ReadLine();
			bool ret = true;
			if (s[0] != 'A') ret = false;
			int count = 0;
			for (int i = 2; i < s.Length - 1; i++) if (s[i] == 'C') count++;
			if (count != 1) ret = false;
			count = 0;
			for (int i = 0; i < s.Length; i++)
			{
				if (s[i] <= 'Z') count++;
			}
			if (count > 2) ret = false;
			Console.WriteLine(ret ? "AC" : "WA");
		}
	}
}

Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    string s;
    cin >> s;
    int ans = 0, c0 = 0, c1 = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '0'){
            if(c1 > 0){
                c1--;
                ans += 2;
            }else{
                c0++;
            }
        }else{
            if(c0 > 0){
                c0--;
                ans += 2;
            }else{
                c1++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
// B - Frog 2
#include <bits/stdc++.h>
using namespace std;

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

	vector<int> h(N+1); for(int i=1; i<=N; i++) cin>>h[i];

	vector<int> dp(N+1);
	for(int n=2; n<=N; n++){
		int m = INT_MAX;
		for(int k=1; k<=min(n-1, K); k++) m = min(m, dp[n-k] + abs(h[n] - h[n-k]));
		dp[n] = m;
	}
	cout<< dp[N] <<endl;
}

Measured memory_bytes: 1024
#include <iostream>                                                                                                       

int N, Y;
int money[3] = {10000, 5000, 1000};

int main(){
   std::cin >> N >> Y;

   int ans[3] = {-1, -1, -1};
   int tmp[3] = {0, 0, 0}; 
   tmp[0] = Y/money[0];
   tmp[1] = (Y - money[0]*tmp[0])/money[1];
   tmp[2] = (Y - money[0]*tmp[0] - money[1]*tmp[1])/money[2];
   while(true){
      int rest = N;
      for(int i=0; i<3; ++i)
         rest -= tmp[i];
      if(rest==0){
         for(int i=0; i<3; ++i)
            ans[i] = tmp[i];
         break;
      }else if(rest<0){
         break;
      }else{
         bool flag = false;
         for(int i=0; i<=tmp[0]; ++i){
            for(int j=0; j<=tmp[1]+2*i; ++j){
               int dif = 1*i + 4*j;
               if(rest==dif){
                  tmp[0] -= i;
                  tmp[1] += 2*i;
                  tmp[1] -= j;
                  tmp[2] += 5*j;
                  i = tmp[0];
                  flag = true;
                  break;
               }   
            }   
         }

         if(!flag) break;
      }

   }


   for(int i=0; i<3; ++i)
      std::cout << ans[i] << ' ';
   std::cout << std::endl;

   return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/dp/tasks/dp_b
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define see(x) cout<<(#x)<<" -> "<<(x)<<"\n"
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
  nimble;
  int tt=1;//cin>>tt;
  while(tt--){
    int n,w;
    cin>>n>>w;
    ll dp[n+1][w+1]={0};
    for(int i=0;i<n;i++)
      for(int j=0;j<=w;j++)dp[i][j]=0;
    vector<pair<int,int>> wv(n);
    repv(wv)
      cin>>wv[i].X>>wv[i].Y;
    for(int i=1;i<=w;i++)
      dp[0][i]=i>=wv[0].X?wv[0].Y:0;
    for(int i=1;i<n;i++)
      for(int j=1;j<=w;j++){
        int x=max(0,j-wv[i].X);
        dp[i][j]=max(dp[i-1][j],(x==0?0:(dp[i-1][x]+wv[i].Y)));
      }
    cout<<dp[n-1][w]<<nl;
  }
  return 0;
}


Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

const int MAX_NM = 100100;
int p[MAX_NM];
bool S[MAX_NM];
bool is_ac[MAX_NM];
int wa_num[MAX_NM];
int N, M;

void init(){
    scanf("%d %d", &N, &M);
    char tmp[3];
    for(int i = 0; i < M; ++i) {
        scanf("%d %s", &p[i], tmp);
        if(strcmp(tmp, "AC") == 0) S[i] = true;
        else S[i] = false;
        --p[i];
    }
    return ;
}

int main()
{
    init();

    //for(int i = 0; i < M; ++i) printf("%d : %d\n", p[i], S[i]);
    int ac = 0, pn = 0;
    for(int i = 0; i < M; ++i) {
        if(S[i]) {
            if(!is_ac[p[i]]) is_ac[p[i]] = true, ++ac, pn += wa_num[p[i]];
        } else {
            ++wa_num[p[i]];
        }
    }
    printf("%d %d\n", ac, pn);
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;


int main () {
    /**
    a + b = x
    2a + 4b = 2y
    */

    int x, y;

    cin >> x >> y;

    for (int i = 0 ; i <= x ; ++ i) {
        if (2 * i + 4 * (x - i) == y) {
            return !printf("Yes");
        }
    }

    printf("No");
}


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

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

  int cnt = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'o')
      cnt++;
  }

  cout << 700 + cnt * 100 << endl;

  return 0;
}


Measured memory_bytes: 256
def dot(a, b):
  return a.real * b.real + a.imag * b.imag

def cross(a, b):
  return a.real * b.imag - a.imag * b.real

def ccw(p0, p1, p2):
  a = p1-p0
  b = p2-p0
  if cross(a,b) > 0:
    return 1 #couner_clockwise
  elif cross(a,b) <0:
    return -1 #clockwise
  elif dot(a,b) < 0:
    return 2 #online_back
  elif abs(a) < abs(b):
    return -2 #online_front
  else:
    return 0 #on_segment

def get_distanceLP(p0,p1,p2):
  return abs(cross(p1 - p0,p2-p0)/abs(p1-p0))

def get_distanceSP(p0,p1,p2):
  if dot(p1-p0,p2-p0)<0:
    return abs(p2-p0)
  if dot(p0-p1,p2-p1)<0:
    return abs(p2-p1)
  return get_distanceLP(p0,p1,p2)

def get_distance(a,b,c,d):
  if intersect(a,b,c,d):
    return 0
  return min(min(get_distanceSP(a,b,c),get_distanceSP(a,b,d)),min(get_distanceSP(c,d,a),get_distanceSP(c,d,b)))

def intersect(a,b,c,d):
  return ccw(a,b,c) * ccw(a,b,d) <=0 and ccw(c,d,a) * ccw(c,d,b) <=0

n=int(input())
for i in range(n):
  x0,y0,x1,y1,x2,y2,x3,y3 = map(int,input().split())
  p0=complex(x0,y0)
  p1=complex(x1,y1)
  p2=complex(x2,y2)
  p3=complex(x3,y3)
  print(get_distance(p0,p1,p2,p3))





Measured memory_bytes: 5656
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = (int) 1e9 + 7;
ll h,w;
char a[1005][1005];
ll dp[1005][1005];
ll solve(ll i, ll j, ll dest_row, ll dest_col){
    if(i > dest_row || j > dest_col || a[i][j] == '#'){
        return 0;
    }
    if(i == dest_row && j == dest_col){
        return 1;
    }
    if(dp[i][j] != -1){
        return dp[i][j];
    }
    dp[i][j] = solve(i+1,j,dest_row,dest_col) + solve(i,j+1,dest_row,dest_col);
    
    dp[i][j]%=mod;

return dp[i][j];
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>a[i][j];
        }
    }
    memset(dp,-1,sizeof(dp));
    cout<<solve(1,1,h,w)<<"\n";
}
    
    


Measured memory_bytes: 9216
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		String seven[] = {
				"0111111",
				"0000110",
				"1011011",
				"1001111",
				"1100110",
				"1101101",
				"1111101",
				"0100111",
				"1111111",
				"1101111"
		};
		while(in.hasNext())
		{
			int n=in.nextInt();
			if(n==-1)
				return;
			String a="0000000";
			for(int i=0;i<n;i++)
			{
				int se=in.nextInt();
				for(int j=0;j<7;j++)
				{
					if(a.charAt(j)!=seven[se].charAt(j))
						System.out.print(1);
					else
						System.out.print(0);
				}
				System.out.println();
				a=seven[se];
			}
		}
	}

}

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

typedef long long ll;
const ll MOD = 1e9+7;
int main () {
    ll N;
    scanf("%lld", &N);
    auto ans = 1LL;
    for(auto i=1; i<=N; i++) {
        ans = (ans*i)%MOD;
    }

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


Measured memory_bytes: 128
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i32 = read(&mut stdin_lock, &mut buf, b'\n');

    let mut o = 0;
    for i in 1..n + 1 {
        if i % 2 != 0 {
            o += 1;
        }
    }
    let ans = o as f32 / n as f32;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int mul(int a, int b) {
	return a*b%13;
}

string s;
int n;
int dp[N][15];
void xuatdp(){
	for(int i=0; i<n; i++){
		for(int j=0; j<13; j++) {
			cerr << dp[i][j] << ' ';
		}
		cerr << endl;
	}
}
int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> s;
	n = s.length();
	int TenPower = 1;
	reverse(s.begin(), s.end());
	if (s[0] == '?') {
		for(int j=0; j<=9; j++) dp[0][j] = 1;
	} else {
		int num = s[0] - '0';
		dp[0][num] = 1;
	}
	// xuatdp();
	for(int i=1; i<n; i++){
		TenPower = mul(TenPower, 10);
		if (s[i] != '?') {
			int num = s[i] - '0';
			for(int j=0; j<=12; j++){
				int x = (j + mul(num, TenPower)) % 13;
				dp[i][x] += dp[i-1][j];
				dp[i][x] %= MOD;
			}
		} else {
			for(int num = 0; num <= 9; num++){
				for(int j=0; j<=12; j++){
					int x = (j + mul(num, TenPower)) % 13;
					dp[i][x] += dp[i-1][j];
					dp[i][x] %= MOD;	
				}
			}
		}
	}
	int ans = dp[n-1][5];
	cout << ans << endl;
	// xuatdp();

	return 0;
}


Measured memory_bytes: 6352
fn main() {
    let a:u32 = read();
    let b:u32 = read();

    println!("{}", if a%2!=0 && b%2!=0 {"Yes"} else {"No"});

}







#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;

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

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  int N;
  cin >> N;
  vector<int> A(N+2);
  REP(i, N) {
    cin >> A[i+1];
  }
  A[0] = A[N+1] = 0;
  ll cost = 0;
  FOR(i, 1, N + 1) {
    cost += abs(A[i] - A[i - 1]);
  }
  FOR(i, 1, N) {
    ll ans = cost - abs(A[i] - A[i - 1]) - abs(A[i + 1] - A[i]) + abs(A[i + 1] - A[i - 1]);
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<VL> t(n, VL(2));
	rep(i, n) cin >>t[i][0] >>t[i][1];
	sort(all(t), [](auto l, auto r){return l[1] < r[1];});
	//cout << w1 - w0 <<"\n";
	
	int cr=0;
	rep(i, n){
		cr += t[i][0];
		if(cr > t[i][1]){
			puts("No"); return 0;
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
int main()
{
    ll n, m;
    cin >> n >> m;
    vector<int> ans(n, 0);
    vp s(m);
    rep(i, m)
    {
        cin >> s[i].first >> s[i].second;
    }
    sort(s.begin(), s.end());
    rep(i, m - 1)
    {
        if (s[i].first == s[i + 1].first && s[i].second != s[i + 1].second)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i, m)
    {
        if (s[i].first == 1 && s[i].second == 0 && n != 1)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    if (n > 1)
    {
        ans[0] = 1;
    }
    rep(i, m)
    {
        ans[s[i].first - 1] = s[i].second;
    }
    rep(i, n)
    {
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n, m; cin >> n >> m;
	vector<int> l(m), r(m); rep(i, m) cin >> l[i] >> r[i];

	int l_max = *max_element(l.begin(), l.end());
	int r_min = *min_element(r.begin(), r.end());
	if (l_max > r_min) {
		printf("0\n");
	} else {
		printf("%d\n", r_min - l_max + 1);
	}
	return 0;
}


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

int main() {
  int A, B, C = 0;
  cin >> A >> B;
  
  for (int i = A; i <= B; i++) {
    int a, b, d, e;
    e = i % 10;
    d = (i / 10) % 10;
    b = (i / 1000) % 10;
    a = i / 10000;
    if (a == e && b == d)
      C++;
  }
  cout << C;
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; 0 <= i; i--)
#define CIN(A) int A; cin >> A;
#define CIN2(A, B) int A, B; cin >> A >> B;
#define CIN3(A, B, C) int A, B, C; cin >> A >> B >> C;
#define CINVEC(A, N) vector<int> A(N); REP(i, N) cin >> A[i]
#define ANS(ans) cout << (ans) << endl
#define SORT(V) sort(V.begin(), V.end())
#define RSORT(V) sort(V.rbegin(), V.rend())

#define DEBUGV(V) REP(i, V.size()) cout << V.at(i) << " "; cout << endl 

int
main()
{
  CIN(N);
  vector<ull> A(N), B(N), C(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  REP(i, N) cin >> C[i];
  
  SORT(A);
  SORT(B);
  SORT(C);

  vector<ull> AB(N+1);
  int index_a = 0;
  AB[0] = 0;
  REP(i, N) {
    AB[i+1] = AB[i];
    while (A[index_a] < B[i] && index_a < N) {
      ++AB[i+1];
      ++index_a;
    }
  }
  REP(i, N) AB[i+1] += AB[i];

  vector<ull> BC(N);
  int index_b = 0;
  REP(i, N) {
    while (B[index_b] < C[i] && index_b < N) {
      ++index_b;
    }
    BC[i] = index_b;
  }

  ull ans = 0;
  REP(i, N) {
    ans += AB[BC[i]];
  }
  
  ANS(ans);

  /*
6
 2 3 6 14 53 159
 6 9 58 79 84 323 
 2 50 79 288 383 2643 

(0 2 3 5 5 5 6)
- 2 5 10 15 20 26 -

(0 2 3 5 6 6)
   5+10+20+26+26
      5  10  16 22
  */


  return 0;
}


Measured memory_bytes: 4224
N, K = map(int, input().split())
candle = list(map(int, input().split()))

#print(candle)

ans = 10 ** 13
if K == 1:
    print(candle[0])
    exit()
# From Left Start
#print("left")
for i in range(N-K+1):
    tmp = abs(candle[i]) + abs(candle[i] - candle[i+K-1])
    #print("_",tmp)
    if tmp < ans:
        ans = tmp
# From Right Start 
#print("right")
for i in range(N-1,K-2,-1):
    tmp = abs(candle[i]) + abs(candle[i] - candle[i-K+1])
    #print("_",tmp)
    if tmp < ans:
        ans = tmp

print(ans)





Measured memory_bytes: 14384
#include<stdio.h>
#include<string.h>
int main(void)
{
    int i,len;
    char s[4096],p[4096],s2[4096];
    scanf("%s",s);
    scanf("%s",p);
    sprintf(s2,"%s%s",s,s);
    puts(strstr(s2,p)==NULL?"No":"Yes");
    return 0;
}




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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  array<int, 3> a, b = {1, 0, -1};
  for (auto &i : a) cin >> i;
  int k;
  cin >> k;
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    int mn = min(k, a[i]);
    ans += mn * b[i];
    k -= mn;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3564
#include <cstdio>
#include <vector>
using namespace std;
const int maxNode = 2e5 + 5;
vector<int> tree[maxNode];
int nbNode, ans[maxNode];
vector<int> col[2], kind[3];
void Dfs(int now, int from, int faCol) {
	col[faCol ^ 1].push_back(now);
	for (int to : tree[now]) {
		if (to == from) continue ;
		Dfs(to, now, faCol ^ 1);
	}
}
int main() {
	scanf("%d", &nbNode);
	for (int edge = 1; edge < nbNode; ++edge) {
		int u, v;
		scanf("%d%d", &u, &v);
		tree[u].push_back(v);
		tree[v].push_back(u);
	}
	for (int num = 1; num <= nbNode; ++num)
		kind[num % 3].push_back(num);
	Dfs(1, -1, 1);
	if (col[0].size() > col[1].size())
		swap(col[0], col[1]);
	if (col[0].size() <= kind[0].size()) {
		int now = 0, pt = 0;
		for (int node : col[0])
			ans[node] = kind[0][pt++];
		if (pt >= kind[0].size()) {
			++now;
			pt = 0;
		}
		for (int node = 1; node <= nbNode; ++node)
			if (!ans[node]) {
				ans[node] = kind[now][pt++];
				if (pt >= kind[now].size()) {
					pt = 0;
					++now;
				}
			}
	} else {
		int pt = 0;
		for (int num : kind[1])
			ans[col[0][pt]] = num, ++pt;
		pt = 0;
		for (int num : kind[2])
			ans[col[1][pt]] = num, ++pt;
		pt = 0;
		for (int node = 1; node <= nbNode; ++node)
			if (!ans[node])
				ans[node] = kind[0][pt++];
	}
	for (int node = 1; node <= nbNode; ++node)
		printf("%d ", ans[node]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 22296
from itertools import product
import numpy as np
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ls = []
    for i in range(N):
        ls.append([A[i], A[i]+1, A[i]-1])
    
    ls = list(product(*ls))
    ans = len(ls)
    for a in ls:
        if np.prod(a) % 2 == 1:
            ans -= 1

    print(ans)

    return

resolve()

Measured memory_bytes: 35036
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v;

ll fep(ll x, ll y, ll mod)
{ll res=1;while(y>0){if(y&1)res=(res*x)%mod;
    y=y>>1;x=(x*x)%mod;}return res%mod;}

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

	ll n,i,m,j,k,x,y,a,b,t;
	string s;
	
	cin >> n;
	for(i=0;i<n;i++)
	{
		cin >> x;
		v.pb(x);
	}
	sort(v.begin(),v.end());
	x=0;
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			for(k=j+1;k<n;k++)
				if(v[i]!=v[j] && v[j]!=v[k] && v[i]+v[j]>v[k])
					x++;
	cout << x;
	return 0;
}


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

#define pb push_back
#define mk make_pair
#define sc second
#define fr first

using namespace std;

typedef long long ll;

const int N = (int) 1e6 + 5;
const int mod = (int) 1e9 + 7;

int n,k,sum,cnt;
int a[N],dp[5005];


bool check(int x) {
        memset(dp,0,sizeof(dp));
        dp[0] = 1;

        for (int i = 1; i <= n; i ++) {
                if(i == x)
                        continue;
                for (int j = k - a[i]; j >= 0; j --) {
                                dp[j + a[i]] |= dp[j];
                }
        }
        for (int i = max(k - a[x],0); i <= k - 1; i ++) {
                if(dp[i] == 1)
                        return true;
        }
        return false;
}
int main () {

        cin >> n >> k;

        for (int i = 1; i <= n; i ++)
                cin >> a[i];

        sort(a + 1,a + n + 1);

        int l = 0, r = n + 1;

        while(r - l > 1) {
                int m = (r + l) >> 1;
                if(check(m))
                        r = m;
                else
                        l = m;
        }
        cout << l << endl;
        return 0;
}


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

int main() {
  map <int, int> dp[2];
  int n, m, t = 0;
  scanf("%d %d", &n, &m);
  dp[t][0] = 0;
  for (int i = 0; i < n; i ++) {
    t ^= 1;
    dp[t].clear();
    int w, v;
    scanf("%d %d", &w, &v);
    for (auto x : dp[t ^ 1]) {
      int wt = x.first, va = x.second;
      dp[t][wt] = max(dp[t][wt], va);
      if (wt + w <= m)
        dp[t][wt + w] = max(dp[t][wt + w], va + v);
    }
  }
  int ans = 0;
  for (auto x : dp[t])
    ans = max(ans, x.second);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//FUNCTION
void solve(void)
{
  int H,W; cin>>H; cin>>W; 
  int x,y; cin>>x; cin>>y;
  double S = double(H*W)/2;
  int check = 0;
  if(2*x == H&&2*y == W)
  {
    check = 1;
  }
  cout<<S<<" "<<check<<endl;
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(15);
  solve();

  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
cnt=0
ln=[]
rn=[]
for i in range (m):
    l,r=map(int,input().split())
    ln.append(l)
    rn.append(r)
ln.sort(reverse=True)
rn.sort()
for i in range (n):
    if ln[0]<=i+1 and rn[0]>=i+1:
        cnt=cnt+1
print(cnt)

    


Measured memory_bytes: 11436
#include <iostream>
#include <cstring>
#include <climits>
using namespace std;

int n;
int x[202], y[202];

int main(){
  while(cin >> n, n){
    int minX = 0;
    int maxX = 0;
    int minY = 0;
    int maxY = 0;

    x[0] = 0;
    y[0] = 0;

    for(int i = 1; i < n; i++){
      int m, d;
      cin >> m >> d;

      if(d == 0){
        x[i] = x[m] - 1;
        y[i] = y[m];
      }
      else if(d == 1){
        x[i] = x[m];
        y[i] = y[m] + 1;
      }
      else if(d == 2){
        x[i] = x[m] + 1;
        y[i] = y[m];
      }
      else{
        x[i] = x[m];
        y[i] = y[m] - 1;
      }

      minX = min(minX, x[i]);
      maxX = max(maxX, x[i]);
      minY = min(minY, y[i]);
      maxY = max(maxY, y[i]);
    }

    cout << maxX - minX + 1 << " " << maxY - minY + 1 << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void){
  int flag=1,j,temp,count=0,N;
  int A[100];
  scanf("%d",&N);
  for(j=0;j<N;j++)
    scanf("%d",&A[j]);
  while(flag){
    flag=0;
    for(j=N-1;j>0;j--){
      if(A[j]<A[j-1]){
        temp=A[j];
        A[j]=A[j-1];
        A[j-1]=temp;
        flag=1;
        count++;
      }
    }
  }
  for(j=0;j<N;j++){
    printf("%d",A[j]);
    if(j!=N-1)printf(" ");
  }
  printf("\n%d\n",count);
  return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  
 int h,w;
  cin >>h>>w;
  char a[60][60]={'.'};
  
  for(int i=1; i<=h; i++){
  	for(int j=1; j<=w; j++){
    	cin >> a[i][j];
    }
  }
  bool imp=0;
  bool ans=1;
  for(int i=0; i<60; i++){
  	for(int j=0; j<60; j++){
    	if(a[i][j]=='#'){
        	if(a[i][j-1]=='.' && a[i][j+1]=='.' && a[i-1][j]=='.' && a[i+1][j]=='.'){
            	imp=1; break;
            }
        }
    }
    if(imp){
      ans=0; break;
    }
  }
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0;i < n;i++)

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

  ll n, y;
  cin >> n >> y;
  rep(i, n+1) {
    rep(j, n+1) {
      ll k = n-i-j;
      if (k >= 0 and 10000*i+5000*j+1000*k == y) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int calc(int N)
{
    if(N==-1) return 0;
    int res=0;
    for(int i=N/4*4;i<=N;i++) res^=i;
    return res;
}

signed main()
{
    int A,B; cin>>A>>B;
    cout<<(calc(B)^calc(A-1))<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 20
#define ll long long
#define lson l,mid,o<<1
#define rson mid+1,r,o<<1|1
#define Ls(o) t[o].ls
#define Rs(o) t[o].rs
#define For(i,x,y) for(int i=(x);i<=(y);++i)
#define Rof(i,x,y) for(int i=(x);i>=(y);--i)
#define Edge(x) for(int i=head[x];i;i=e[i].nxt)
#define mcpy(x,y) memcpy(x,y,sizeof(x))
#define mset(x,y) memset(x,y,sizeof(x))
using namespace std;
int ans=1e9,t,n,m,fa[N],a[N][N],_; //全局最优解、温度
const double delta=0.993; //降温系数
vector<int> g[N];
bool vis[N],use[N*N],p[N][N];
struct ed{ int u,v,w; }e[N*N],tmp[N*N];
void dfs(int x,int f){
	fa[x]=f;
	for(auto to:g[x]) if(to!=f) dfs(to,x);
}
bool cmp(const ed &x,const ed &y){ return x.w>y.w; }
void dfs2(int rt,int x,int f,int cnt){
	if(cnt<=1 && ~a[x][rt] && !p[x][rt] && !(vis[x] && vis[rt]) && f!=rt) _+=a[x][rt];
	for(auto to:g[x]) if(to!=f) dfs2(rt,to,x,cnt+vis[to]);
}
int find(int x){ return x==fa[x]?x:fa[x]=find(fa[x]); }
int solve(){
	int tot=0;_=0;
	For(i,1,n) fa[i]=i,vis[i]=0;
	For(i,1,n) For(j,1,n) p[i][j]=0;
	For(i,1,m) use[i]=0;
	For(i,1,m){
		int u=find(tmp[i].u),v=find(tmp[i].v);
		if(u==v) continue;
		if(u>v) swap(u,v);fa[v]=u;
		tot+=tmp[i].w,use[i]=1,p[tmp[i].u][tmp[i].v]=p[tmp[i].v][tmp[i].u]=1;
	}
	For(i,1,n) g[i].clear();
	For(i,1,m) if(use[i]) g[tmp[i].u].push_back(tmp[i].v),g[tmp[i].v].push_back(tmp[i].u);
	For(i,1,n) fa[i]=0;
	dfs(1,0);
	for(int i=n;i;i=fa[i]) vis[i]=1;
	For(i,1,n) dfs2(i,i,0,vis[i]);
	tot+=_/2;
	return tot;
}
void Rand(){
	random_shuffle(tmp+1,tmp+m+1);
	ans=max(ans,solve());	
}
int main(){
	int qwq=0,u,v,w;
	srand(20000000);srand(rand());srand(rand());
	scanf("%d%d",&n,&m);
	mset(a,-1);
	For(i,1,m){
		scanf("%d%d%d",&u,&v,&w);
		e[i]=(ed){u,v,w},qwq+=w,a[u][v]=a[v][u]=w;
		tmp[i]=e[i],g[u].push_back(v),g[v].push_back(u);
	}
	sort(e+1,e+m+1,cmp);
	For(i,1,m) tmp[i]=e[i];
	ans=solve();
	For(i,1,500500) Rand();
	printf("%d\n",qwq-ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define N (1<<20)
using namespace std;
typedef long long ll;
string str;
int bit[N+1],n;
int a[N];

int sum(int i){
  int res=0;
  while(i>0){
    res+=bit[i];
    i-=i&-i;
  }
  return res;
}

void add(int i,int x){
  while(i<=n){
    bit[i]+=x;
    i+=i&-i;
  }
}

ll solve(){
  n=str.size();
  int cnt[30]={},cnt2[30]={};
  for(int i=0;i<n;i++)cnt[str[i]-'a']++;
  for(int i=0;i<30;i++)if(cnt[i]%2)return -1;
  
  int A=0;
  stack <int> stk[30];
  
  for(int i=0;i<n;i++){
    int idx=str[i]-'a';
    if(cnt[idx]/2>cnt2[idx]){
      stk[idx].push(A);
      A++;
      cnt2[idx]++;
      a[i]=A;
    }
    else {
      a[i]=n-stk[idx].top();
      stk[idx].pop();
    }
  }

  ll ans=0;
  for(int j=0;j<n;j++){
    ans+=j-sum(a[j]);
    add(a[j],1);
  }
  return ans;
}


int main(){
  cin>>str;
  reverse(str.begin(),str.end());
  cout <<solve()<<endl;  
  return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> cnt(n, 0);
    int a, b;
    for (int i = 0; i < m; i++){
        cin >> a >> b;
        a--; b--;
        cnt[a]++; cnt[b]++;
    }
    int odd = 0;
    for (int i = 0; i < n; i++) if (cnt[i] % 2) odd++;
    if (odd) cout << "NO" << endl;
    else cout << "YES" << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> b(n);
  rep(i,n) cin >> b[i];
  vector<int> c(n-1);
  rep(i,n-1) cin >> c[i];
  rep(i,n) a[i]--;

  int ans = 0;
  rep(i,n) {
    ans += b[a[i]];
  }

  rep(i,n-1) {
    if (a[i]+1 == a[i+1]) {
      ans += c[a[i]];
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

    int k, a, b;
    cin >> k >> a >> b;
    bool flag = false;
    for(int i = a; i<=b; i++)
    {
        if(i%k == 0)
        {
            flag = true;
            break;
        }
    }
    if(flag)
        cout << "OK" << endl;
    else 
        cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3640
def main():
    a, b, c = map(int, input().split())
    hidari = (c - a - b) ** 2
    migi = 4 * a * b
    if (migi < hidari) and ((c-a-b)>0):
        print("Yes")
    else:
        print("No")
    return 0


if __name__ == '__main__':
    main()

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

int main() {
	int a[] = { 0,1,3,1,2,1,2,1,1,2,1,2,1 };
	int x, y;
	cin >> x >> y;

	cout << (a[x] == a[y] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import fractions
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
s=0
for i in range(1,n):
    ans=ans*a[i]// fractions.gcd(ans,a[i])
for i in range(n):
    s+=ans//a[i]
s=s%1000000007
print(s)

Measured memory_bytes: 6072
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-11
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

int main(){
  char ss[110];
  int a,b;
  map<int,int> cnt;
  set<int> po,poo;
  while(gets(ss)){
    if(ss[0]=='\0')break;
    sscanf(ss,"%d,%d",&a,&b);
    cnt[a]++;
    poo.insert(a);
  }
  while(gets(ss)){
    if(ss[0]=='\0')break;
    sscanf(ss,"%d,%d",&a,&b);
    cnt[a]++;
    if(poo.count(a))po.insert(a);
  }
  set<int>::iterator iter = po.begin();
  while(iter!=po.end()){
    printf("%d %d\n",*iter,cnt[*iter]);
    ++iter;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
 
int main() {
 
int al[30] = {0};
char b[2000]= {0};
int i,j,n;
 
i=0;
 
while( scanf("%c",&b[i]) != EOF) {
 
if (b[i] >= 'A' && 'Z' >= b[i] ) {
n = b[i] - 'A';
al[n] += 1;
 
} else if(b[i] >=  'a' && b[i] <= 'z' ) {
n = b[i] - 'a';
al[n] += 1;
}
i=i+1;
}
 
for(j=97; j<=122; j++) {
n = j - 'a';
printf("%c : %d\n",j,al[n]);
}
 
return 0;
 
}


Measured memory_bytes: 2112
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  string s;
  ll k;
  cin>>k>>s;
  if(k>=s.length()) cout<<s<<endl;
  else cout<<s.substr(0,k)+"..."<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <vector>
#include <sstream>
#include <map>
#include <algorithm>
#include <utility>

using namespace std;

bool cmp(const pair<int,int> &a,const pair<int,int> &b){
    return a.second < b.second;
}

void solve(vector<vector<int> > v){
    map<int,int> point2num;
    vector<pair<int,int> > points;
    for(int i=0;i<v.size();i++){
        int num = v[i][0];
        vector<int> frame(11);
        frame[0] = 0;
        int f=1;int j=1;
        while(true){
            if(f==11)break;
            int x = v[i][j];
            if(x==10){
                frame[f]=10+v[i][j+1]+v[i][j+2];
                f++;j++;
                continue;
            }
            j++;
            x = x+v[i][j];
            if(x==10){
                frame[f]=10+v[i][j+1];
                f++;j++;
                continue;
            }
            frame[f] = x;
            f++;j++;
            continue;
        }
        int p=0;
        for(int j=0;j<frame.size();j++){
            p+=frame[j];
        }
        points.push_back(make_pair(num,p));
    }
    sort(points.begin(),points.end());
    reverse(points.begin(),points.end());
    stable_sort(points.begin(),points.end(),cmp);
    reverse(points.begin(),points.end());
    for(int i=0;i<points.size();i++){
        cout << points[i].first << " " << points[i].second << endl;
    }
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        cin.ignore();
        vector<vector<int> > v(n);
        for(int i=0;i<n;i++){
            string s;
            getline(cin,s);
            istringstream is(s);
            int x;
            while(is >> x){
                v[i].push_back(x);
            }
        }
        solve(v);
    }
}

Measured memory_bytes: 0
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	a := []int{}
	s := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		s.Scan()
		aa, _ := strconv.Atoi(s.Text())
		a = append(a, aa)
	}

	shellSort(n, a)
}

func shellSort(n int, a []int) {
	cnt := 0

	g := []int{}
	for i := 2; i <= n+1; i *= 2 {
		g = append([]int{i-1}, g...)
	}
	m := len(g)

	for i := 0; i < m; i++ {
		var c int
		a, c = insertionSort(n, a, g[i])
		cnt += c
	}

	fmt.Println(m)
	fmt.Print(g[0])
	for i := 1; i < m; i++ {
		fmt.Print(" ")
		fmt.Print(g[i])
	}
	fmt.Println()
	fmt.Println(cnt)
	for i := 0; i < n; i++ {
		fmt.Println(a[i])
	}
}

func insertionSort(n int, a []int, g int) ([]int, int) {
	cnt := 0
	for i := g; i < n; i++ {
		v := a[i]
		j := i-g
		for ; j >= 0; j = j-g {
			if a[j] > v {
				a[j+g] = a[j]
				cnt++
			} else {
				break
			}
		}
		a[j+g] = v
	}
	return a, cnt
}



Measured memory_bytes: 24508