akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<iomanip>
#include<cmath>
#define pi 3.14159265358979323846
#define mod 1000000007
#define int long long
#define elif else if
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
signed main(){
  int n = 1, c = 1, cc = 0;
  char a[4], b;
  cin >> a[0];
  rep(i, 1, 4){
    cin >> a[i];
    if(a[i] != a[0] && n == 1){
      n++;
      cc++;
      b = a[i];
    }
    elif(a[i] == b){
      cc++;
    }
    elif(a[i] == a[0]){
      c++;
    }
  }
  if(c == 2 && cc == 2){
    cout << "Yes\n";
    return 0;
  }
  cout << "No\n";
}
      


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    string s;
    cin >> s;
    for(int i =0; i< s.size(); i++){
        s[i] = 'x';
    }
    cout << s << endl;
    return 0;
}

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
    int k;  cin >> k;
    string s;   cin >> s;
    int n = s.size();
    mint ans = 0;
    combination c(n+k);
    for(int i = 0; i <= k; i++){
        mint now = mint(26).pow(k-i);
        now *= mint(25).pow(i);
        now *= c(i+n-1, n-1);
        ans += now;
    }
    cout << ans << endl;
}


Measured memory_bytes: 35532
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long K = sc.nextLong();
		sc.close();
		long p = N % K;
		// System.out.println("p = " + p);
		// System.out.println("abs = " + Math.abs(p - K));
		// System.out.println(1000000000000000000L - 1);
		// 1000000000000000000 999999999999999999
		System.out.println(Math.min(Math.min(p, Math.abs(p - K)), N));
	}
}

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

#define ll long long
#define MAXN (100010)

int n, x;
ll a[MAXN];

int main(){
	scanf("%d%d", &n, &x);
	for(int i = 1; i <= n; ++ i){
		scanf("%lld", a + i);
	}
	ll ans = 0;
	for(int i = 2; i <= n; ++ i){
		if(a[i] + a[i - 1] <= x) continue;
		if(a[i] >= a[i] + a[i - 1] - x){
			ans += a[i] + a[i - 1] - x;
			a[i] -= a[i] + a[i - 1] - x;
		}
		else{
			ans += a[i];
			a[i] = 0;
			ans += a[i - 1] - x;
			a[i - 1] -= a[i - 1] - x;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
int main(){
  int i;
  int n;
  double a;
  for(;;){
    scanf("%d",&n);
    if(n==-1)
      break;
    a=0.0;
    for(i=1;i<n;i++)
      a+=atan2(1,sqrt(i));
    printf("%.2lf\n%.2lf\n",cos(a)*sqrt(n),sin(a)*sqrt(n));
  }
  return 0;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> edges[100000];
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    vector<int> ans(N), visited(N);
    visited[0] = 1;
    queue<int> que;
    que.push(0);
    while(que.size()){
        int i = que.front(); que.pop();
        for(int j : edges[i]) if(!visited[j]){
            ans[j] = i;
            visited[j] = 1;
            que.push(j);
        }
    }
    cout << "Yes" << endl;
    for(int i=1; i<N; i++) cout << ans[i]+1 << endl;
    return 0;
}


Measured memory_bytes: 10636
#include<stdio.h>

int main(void)
{
    int h,n;
    int i;
    int waza,damage=0;
    
    scanf("%d%d",&h,&n);
    for(i=0; i<n; i++){
        scanf("%d",&waza);
        damage+=waza;
    }
    if(h<=damage){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<set>
int main()
{
	int n,m,k,b,r,p,q,bunny[51],i;
	std::set<int>s;
	scanf("%d%d",&n,&k);
	for(i=0;i<k;++i)
	{
		scanf("%d",&m);
		while(m--)
		{
			scanf("%d",&b);
			bunny[b]=i;
		}
	}
	scanf("%d",&r);
	while(r--)
	{
		scanf("%d%d",&p,&q);
		if(bunny[p]==bunny[q])
			s.insert(p),s.insert(q);
	}
	printf("%d\n",(int)s.size());
	return 0;
}

Measured memory_bytes: 1032
#include<iostream>
#include<cmath>
using namespace std;
bool prime(int x){
  for(int i=2;i<=sqrt((double)x);i++){
    if(x%i==0)return false;
  }
  return true;
}

int main(){
  int n;
  while(cin>>n,n){
    int sum=0;
    for(int i=2;n>=1;i++){
      if(prime(i)){sum+=i;n--;}
    }
    cout<<sum<<endl;
  }
}
    

Measured memory_bytes: 1160
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
left,right = [a[0]]+[0]*(n-1),[0]*(n-1)+[a[n-1]]
arr = [0]*n
for i in range(0,n-1):
  left[i+1] = gcd(left[i],a[i+1])
  right[n-2-i] = gcd(right[n-1-i],a[n-2-i])
arr[0] = right[1]
arr[n-1] = left[n-2]
for i in range(1,n-1):
  arr[i] = gcd(left[i-1],right[i+1])
print(max(arr))

Measured memory_bytes: 16132
import java.util.*;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0118#
public class Main {
    class Point {
        int x, y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public String toString() {
            return this.x + ", " + this.y;
        }

    }

    int h, w, n;
    char[][] field;
    Point start;
    int goal;
    int[] dx = {1, 0, -1, 0};
    int[] dy = {0, 1, 0, -1};


    void run() {
        Scanner sc = new Scanner(System.in);
        h = sc.nextInt();
        w = sc.nextInt();
        n = sc.nextInt();
        field = new char[h][w];

        for (int i = 0; i < h; i++) {
            char[] chars = sc.next().toCharArray();
            for (int j = 0; j < w; j++) {
                field[i][j] = chars[j];
                if (chars[j] == 'S') {
                    start = new Point(i, j);
                }
            }
        }
        int count = 0;
        for (int i = 1; i <= n; i++) {
            boolean[][] visited = new boolean[h][w];
            goal = i;
            List<Point> l = new ArrayList<>();
            l.add(start);
            visited[start.x][start.y] = true;
            int step = 0;
            while (!l.isEmpty()) {
                List<Point> next = new ArrayList<>();
                for (Point p : l) {
                    if (Character.getNumericValue(field[p.x][p.y]) == goal) {
                        count += step;
                        start = new Point(p.x, p.y);
                        next.clear();
                        break;
                    }
                    for (int j = 0; j < 4; j++) {
                        int nx = p.x + dx[j];
                        int ny = p.y + dy[j];
                        if (0 <= nx && nx < h && 0 <= ny && ny < w && !visited[nx][ny] && field[nx][ny] != 'X') {
                            next.add(new Point(nx, ny));
                            visited[nx][ny] = true;
                        }
                    }
                }
                step++;
                l = next;
            }
        }
        System.out.println(count);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}



Measured memory_bytes: 100800
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
string a;
signed main()
{
	cin>>a;
	rep(i,4){
		cout<<a[i];
	}
	cout<<" ";
	rep(i,8){
		cout<<a[i+4];
	}
	cout<<endl;
}

Measured memory_bytes: 256
// Author: 23forever
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
typedef long long LL;
const int MAXN = 300000;
const int INF = 0x3f3f3f3f;
using namespace std;

inline void enableFileIO() {
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
}

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int a[MAXN + 5], n;

void init() {
//  enableFileIO();
  
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
}

inline bool chk(int x, int y) {
  int mx = 0, mn = INF;
  for (int i = x; i <= y; ++i) {
    mx = max(mx, a[i]);
    mn = min(mn, a[i]);
  }
  if (mx != y || mn != x) return false;
  
  mx = 0;
  int mx2 = 0;
  for (int i = x; i <= y; i += 2) {
    if (mx < a[i]) {
      mx = a[i];
    } else if (mx2 < a[i]) {
      mx2 = a[i];
    } else {
      return false;
    }
  }
  return true;
}

int main() {
  init();

  int j;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == i) continue;

    for (j = i; j <= n - 2; j += 2) {
      if (a[j + 1] != j + 1 || a[j + 2] == j + 2) break;
    }
    if (!chk(i, j)) {
      puts("No");
      return 0;
    }
    i = j;
  }

  puts("Yes");
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,A,B;
  cin>>N>>A>>B;
  cout<<min(N*A,B)<<endl;
}


Measured memory_bytes: 256
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def main():
    n, d = map(int, input().split())
    d = d * d
    a =[list(map(int, input().split())) for i in range(n)]
    s = 0
    for x, y in a:
        if x * x + y * y <= d:
            s += 1
    print(s)

main()


Measured memory_bytes: 45772
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int r = 0;
		if(n < 600){
			r = 8;
		}else if(n < 800){
			r = 7;
		}else if(n < 1000){
			r = 6;
		}else if(n < 1200){
			r = 5;
		}else if(n < 1400){
			r = 4;
		}else if(n < 1600){
			r = 3;
		}else if(n < 1800){
			r = 2;
		}else{
			r = 1;
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 35552
#include<iostream>
#include<algorithm>
#include<vector>
#include <cmath>
#include <limits>
#include <iomanip>
using namespace std;
const long long INF=20000000000;
typedef long long ll;

int main(){
	ll N,W;
	cin>>N>>W;
	ll w[N];
	ll v[N];
	for(int i=0;i<N;i++)cin>>w[i]>>v[i];
	
	ll dp[N+2][W+2];
	//init
	for(int i=0;i<N+2;i++){
		for(int j=0;j<W+2;j++)
			dp[i][j]=0;
	}
	//i
	dp[0][0]=0;
	//dp[0][w[0]]=v[0];
	
	for(ll i=0;i<N;i++){
		for(ll j=0;j<=W;j++){
			if(j+w[i]<=W && i+1<=N)
				dp[i+1][j+w[i]]=max(
					dp[i+1][j+w[i]]
					,dp[i][j]+v[i]);
			
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
		}
	}
	
	/*for(int i=0;i<=N;i++){
		for(int j=0;j<=W;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}*/
	
	/*ll ans=0;
	for(ll j=0;j<=W;j++)ans=max(ans,dp[N-1][j]);
	cout<<ans;*/
	cout<<dp[N][W]<<endl;
}

Measured memory_bytes: 79872
#include <stdio.h>

int gcd(int x, int y) {
  if (y) {
    gcd(y, x % y);
  } else {
    return x;
  }
}

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

  printf("%d\n", gcd(x, y));
  return 0;
}


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

#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.end()
#define inf 1e9
#define Puts(x) puts(x? "YES":"NO")
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int n;
  cin >> n;
  vi dp(n + 1);
  dp[0] = 0;
  rep(i, 1, n + 1) {
    dp[i] = dp[i - 1] + 1;

    int six = 6;
    while(six <= i) {
      dp[i] = min(dp[i], dp[i - six] + 1);
      six *= 6;
    }

    int nine = 9;
    while(nine <= i) {
      dp[i] = min(dp[i], dp[i - nine] + 1);
      nine *= 9;
    }
  }
  cout << dp[n] << endl;
}


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

int main(){
    int N,M,X,Y;
    cin>>N>>M>>X>>Y;
    vector<int>x(N+1);
    vector<int>y(M+1);
    x[0]=X;y[0]=Y;
    for(int i=1;i<N+1;i++){cin>>x[i];}
    for(int i=1;i<M+1;i++){cin>>y[i];}
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    if(y[0]>x[N]){cout<<"No War"<<endl;}
    else{cout<<"War"<<endl;}
}

Measured memory_bytes: 256
import queue

N = int(input())
G = []
for _ in range(N):
    u, n, *K = map(int, input().split())
    G.append((u - 1, [k - 1 for k in K]))

Q = queue.Queue()
Q.put(G[0])
dist = [-1] * N
dist[0] = 0
while not Q.empty():
    U = Q.get()
    for u in U[1]:
        if dist[u] == -1:
            Q.put(G[u])
            dist[u] = dist[U[0]] + 1

for i, time in enumerate(dist):
    print(i + 1, time)



Measured memory_bytes: 6876
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }


ll ansc,ansd,anse,ansf;


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

  ansc = pow(10,9);
  ansd = 1;
  ansf = s/pow(10,9)+1;
  anse = ansc*ansf-s;

  if(s==pow(10,18)){
	ansd = 0;
	anse = 0;
	ansf = pow(10,9);
  }

  cout << 0 << " " << 0 << " " << ansc << " " << ansd << " " << anse << " " << ansf << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int N, M;
  cin >> N >> M;
  vector<long int> a(M);
  vector<long int> b(M);
  vector<bool> ab(M);

  long int tmpm = 0;;
  long int sum = 0;
  int count = 0;

  for(int i=0;i<M;i++){
   cin >> a.at(i) >> b.at(i);
    ab.at(i) = true;
    tmpm++;
  }
  
// 切断しながらカウントしながら再ソート
//　✓は最大でM回だから
  for(long int i=0;i<M;i++){
    vector<long int> ca(tmpm);
    vector<long int> cb(tmpm);
    count = 0;
    
    //生きてるa bだけコピー
    for(long int j=0;j<M;j++){
      if(ab.at(j)){
        ca.at(count) = a.at(j);
        cb.at(count) = b.at(j);
        count++;
      }
    }
    
    //bの最小を探す
    sort(cb.begin(),cb.end());
    
    //bの最小の手前で切断する．切断されると生存数が減る
    for(long int j=0;j<M;j++){
      if((a.at(j) < cb.at(0)) && ab.at(j) ){
      	ab.at(j) = false;
        tmpm--;
      }
    }
    sum++;
    //残存結合がなくなったらブレーク
    if(tmpm==0) break;
  }  
    
  cout << sum << endl;
}

Measured memory_bytes: 3440
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    double a,b,h,m;cin>>a>>b>>h>>m;
    double hour=(h*60+m)*PI/360.0;
    double minn=m*PI/30.0;
    double rad=abs(hour-minn);
    cout<<fixed<<setprecision(12)<<sqrt(a*a+b*b-2*a*b*cos(rad));
}

Measured memory_bytes: 4168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll N;
//02:36
ll p[40], t[40];
ll dp[40][3];
void solve() {
    for(int i = 0; i < N; i++) {
        cin >> p[i] >> t[i];
        for(int j = 0; j < 3; j++) {
            dp[i][j] = 1e18;
        }
    }
    if(p[0] > t[0]) {
        cout << "NG 1" << endl;
        return;
    }
    dp[0][0] = p[0];
    for(int i = 1; i < N; i++) {
        ll deltat = t[i] - t[i-1];
        ll deltap = abs(p[i] - p[i-1]);
        for(int before = 0; before < 3; before++) {
            if(before != 2 and (before + 2) * deltap <= deltat) {
                chmin(dp[i][before+1], dp[i-1][before] + deltap);
            }
            if(p[i-1] * (before+2) + p[i] <= deltat) {
                chmin(dp[i][0], dp[i-1][before] + p[i-1] + p[i]);
            }
        }
    }
    for(int i = 0; i < N; i++) {
        ll ans = 1e18;
        for(int j = 0; j < 3; j++) chmin(ans, dp[i][j]);
        if(ans == 1e18) {
            cout << "NG " << i + 1 << endl;
            return;
        }
    }
    cout << "OK ";
    ll ans = 1e18;
    for(int j = 0; j < 3; j++) chmin(ans, dp[N-1][j]);
    cout << ans + p[N-1] << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N) {
        if(N == 0) break;
        solve();
    }
    return 0;
}


Measured memory_bytes: 3116
fun main(args: Array<String>) {
    abc140c()
}

fun abc140c() {
    val n = readLine()!!.toInt()
    val bList = readLine()!!.split(" ").map { it.toInt() }

    var answer = bList.first() + bList.last()
    for (i in 1 until bList.size) {
        val before = bList[i - 1]
        val current = bList[i]
        answer += Math.min(before, current)
    }

    println(answer)
}


Measured memory_bytes: 38068
def nibutan(n, M):
  ok = 0
  ng = M + 1
  while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    #print("value:", mid)
    if nasu(mid) >= n:
      ok = mid
    else:
      ng = mid
  return ok

def nasu(x):
  ans = 0
  for i in A:
    #print("L:", i, end = " ")
    t = N - hogetan(x - i)
    #print("n:", t)
    ans += t
  return ans

def hogetan(n):
  ok = N
  ng = -1
  while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if A[mid] >= n:
      ok = mid
    else:
      ng = mid
  return ok

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


A.sort()
MAX = A[-1] + A[-1]
inf = MAX + 10

t = nibutan(M, MAX)
mi = inf
cnt = 0
ans = 0
for i in A:
  k = hogetan(t - i)
  n = N - k
  cnt += n
  if n != 0:
    mi = min(mi, i + A[k])
  ans += n * 2 * i

ans -= mi * (cnt - M)

print(ans)

Measured memory_bytes: 54912
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

a,b,c,d=map(int,input().split())
if abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
# -*- coding: utf-8 -*-


N, M  =  [int(i) for i in input().split()]
H  =  [int(i) for i in input().split()]

ans = [1]*N
for i in range(M):
    a,b = [int(i) for i in input().split()]
    if H[a-1] <= H[b-1]:
        ans[a-1] = 0
    if H[a-1] >= H[b-1]:
        ans[b-1] = 0
print(sum(ans))


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

int main(){
int M, D, D1, D2, count;
  cin >> M >> D;
  D1 = D / 10;
  D2 = D % 10;
  for(int i = 2; i < D1; i++){
    for(int j = 2; j < 10; j++){
      if(i * j < M + 1)
        count++;
    }
  }
  for(int i = 2; i < D2 + 1; i++){
    if(D1 * i < M + 1)
      count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
#include<string>
#include<cstring>
#include<ctype.h>
using namespace std;

typedef long long ll;
typedef long l;

#define EPS 1e-9
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define umpit unordered_map<ll,ll>::iterator
#define mpit map<ll,ll>::iterator
#define setit set<ll,ll>::iterator
#define all(v) v.begin(),v.end()
//All divisors of 1 to n
ll func(vector<ll>v, ll x){
	vector<ll>::iterator it;
	it = upper_bound(all(v),x);
	return (it - v.begin());
}
vector<ll>temp;
void primeFactors(ll n)
{
    while (n % 2 == 0)
    {
        temp.pb(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            temp.pb(i);
            n = n/i;
        }
    }
    if (n > 2)
        temp.pb(n);

	//do what you want with vector<ll>
}

int main()
{
	ll n;
	cin>>n;
	vector<ll>v;
	FOR(i,1,10000){
		v.pb(( (i)*(i+1) )/2);
	}
	temp.clear();
	primeFactors(n);
	set<ll>s1;
	map<ll,ll>mp1;
	FOR(i,0,temp.size()){
		mp1[temp[i]]++;
		
	}
	ll sum = 0;
	for(auto i: mp1){
		sum += func(v,i.ss);
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3844
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

L, R, d = MAP()
cnt = 0
for i in range(L, R+1):
    if i % d == 0:
        cnt += 1

print(cnt)

Measured memory_bytes: 9968
#include <stdio.h>
#include <algorithm>

using namespace std;

template<class T>T pow2(T x_)
{
	if (x_ == 0)return 1;
	T ans = pow2(x_ / 2);
	return ans * ans * ((x_ % 2) ? 2 : 1);
}

int senflag[10][10000];

int main()
{
	for (;;)
	{
		int r, c;
		scanf("%d %d", &r, &c);
		if (r == 0 && c == 0)break;
		for (int y = 0; y < r; ++y)
		{
			for (int x = 0; x < c; ++x)
			{
				scanf("%d",&senflag[y][x]);
			}
		}
		auto limit = pow2(r);
		int ans = 0;
		for (int i = 0; i < limit; ++i)
		{
			int totnum = 0;
			for (int x = 0; x < c; ++x)
			{
				int colnum = 0;
				for (int y = 0; y < r; ++y)
				{
					if ((senflag[y][x]) ^ (i >> y & 1))
					{
						++colnum;
					}
				}
				totnum += max(colnum, r - colnum);
			}
			ans = max(ans, totnum);
		}
		printf("%d\n", ans);
		
	}
	return 0;
}

Measured memory_bytes: 2960
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)



int main(void){
	string s;
	cin>>s;
	ll dp[100005][3];
	rep(i,100005){
		rep(j,3){
			dp[i][j] = 0;
		}
	}
	ll hatena = 1;
	if(s[0] == 'A'){
		dp[0][0] = 1;
	}else if(s[0] == '?'){
		dp[0][0] = 1;
		hatena = 3;
	}
	reps(i,s.size()-1){
		if(s[i] == 'A'){
			dp[i][0] += hatena;
		}else if(s[i] == 'B'){
			dp[i][1] += dp[i-1][0];
		}else if(s[i] == 'C'){
			dp[i][2] += dp[i-1][1];
		}else{
			dp[i][0] += hatena;
			dp[i][1] += dp[i-1][0];
			dp[i][2] += dp[i-1][1];
			hatena *= 3;
			hatena %= MOD;
		}
		rep(j,3){
			dp[i][j] += dp[i-1][j];
			if(s[i] == '?'){
				dp[i][j] += dp[i-1][j];
				dp[i][j] += dp[i-1][j];
			}
			dp[i][j] %= MOD;
		}
	}
	cout<<dp[s.size()-1][2]<<endl;
	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int A, B, H, M;
	cin >> A >> B >> H >> M;

	double H_kakudo = (double)(H + ((double)M / (double)60)) / (double)12 * 360;
	double M_kakudo = (double)M / (double)60 * 360;
	double diff_kakudo = min(abs(H_kakudo - M_kakudo), (360 - abs(H_kakudo - M_kakudo)));

	// debug(diff_kakudo);
	const double pi = 3.141592653589793;
	double cos_HM = cos(2 * pi * diff_kakudo / 360);

	// debug(cos_HM);

	double yogen = pow(A, 2) + pow(B, 2) - 2 * A * B * cos_HM;
	cout << sqrt(yogen) << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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


void solve(long long K, long long A, long long B){
    for (long long i = A; i <= B; i++) {
        if (i % K == 0){
            cout << "OK" << endl;
            return;
        }
    }
    cout << "NG" << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(K, A, B);
    return 0;
}


Measured memory_bytes: 3688
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  k,x=LI()

  if k*500>=x:
    return 'Yes'
  return 'No'

# main()
print(main())


Measured memory_bytes: 6860
#include<stdio.h>
int main(void)
{
  int x,y,z,tmp;
  scanf("%d",&x);
  scanf("%d",&y);
  if(y>x)
  {
    tmp=x;
    x=y;
    y=tmp;
  }
  while(y!=0)
  {
    z=x%y;
    x=y;
    y=z;
  }
  printf("%d\n",x);
  return 0;
}



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

using namespace std;

int main()
{

  long long  N;
  cin >> N;

  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  long long x0 = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      x0 += A[i];
    }
    else {
      x0 -= A[i];
    }    
  }
  cout << x0 << " ";
for (int i = 1; i < N; ++i) {
    long long xi = 2*(A[i - 1] - x0 / 2);
    cout << xi << " ";
    x0 = xi;
  }
  return 0;
}


Measured memory_bytes: 2048
use std::collections::HashSet;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, m): (usize, usize) = parse!(it, 2);
    let mut g = vec![vec![]; n];
    for _ in 0..m {
        let (a, b): (usize, usize) = parse!(it, 2);
        g[a - 1].push(b - 1);
    }

    let mut cycles = vec![];
    let mut parents = vec![std::usize::MAX; n];
    let mut seen = vec![Unseen; n];
    for start in 0..n {
        if seen[start] == Unseen {
            seen[start] = Seen;
            dfs(&g, start, &mut seen, &mut parents, &mut cycles);
        }
    }
    'outer: for cycle in cycles {
        for &i in cycle.iter() {
            let mut count = 0;
            for j in g[i].iter() {
                if cycle.contains(j) {
                    count += 1;
                }
            }
            if count > 1 {
                continue 'outer;
            }
        }
        println!("{}", cycle.len());
        for i in cycle {
            println!("{}", i + 1);
        }
        return;
    }
    println!("{}", -1);
}

fn get_cycle(parents: &Vec<usize>, start: usize, end: usize) -> HashSet<usize> {
    let mut ret = HashSet::new();
    let mut cur = end;
    while cur != start {
        ret.insert(cur);
        cur = parents[cur];
    }
    ret.insert(start);
    ret
}

fn dfs(
    g: &Vec<Vec<usize>>,
    u: usize,
    seen: &mut Vec<State>,
    parents: &mut Vec<usize>,
    cycles: &mut Vec<HashSet<usize>>,
) {
    for &v in g[u].iter() {
        match seen[v] {
            Unseen => {
                seen[v] = Seen;
                parents[v] = u;
                dfs(g, v, seen, parents, cycles);
            }
            Seen => {
                cycles.push(get_cycle(parents, v, u));
            }
            _ => (),
        }
    }
    seen[u] = Checked;
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum State {
    Unseen,
    Seen,
    Checked,
}
use State::*;

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4476
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <cmath>
#define rep(i,N) for(int i=0; i<N;i++)
using namespace std;

int main(){
    long int X,K,D;
    cin>>X>>K>>D;
    //  value V:= |X+D*x-D*y|
    //       where x+y=K x>=0 and y>=0
    //  => y=x+X/D-V/D
    //    or=x+X/D+V/D
    //
    //  => -x+K=x+X/D (-+)V/D => x=K/2-X/2D (+-)V/2D, y=K/2+X/2D (-+)V/2D V=
    //  7 4 3
    //  X K D
    //  x=2-7/6=0.8333, y=3.1666 四捨五入して x=1, y=3(+Dを1回, -Dを3回)
    //
    long int x=round(K/2.0-X/2.0/D);
    long int y=round(K/2.0+X/2.0/D);
    if(x<0){
        x=0;
        y=K;
    }else if(y<0){
        x=K;
        y=0;
    }

    long int V=abs(X+D*x-D*y);
    if(x+y>K){
        long int V1=abs(X+D*(x-1)-D*y);
        long int V2=abs(X+D*x-D*(y-1));
        if(V1>=V2){
            V=V2;
        }else{
            V=V1;
        }
    }else if(x+y<K){
        long int V1=abs(X+D*(x+1)-D*y);
        long int V2=abs(X+D*x-D*(y+1));
        if(V1>=V2){
            V=V2;
        }else{
            V=V1;
        }
    }

   // cout<<x<<" "<<y<<" "<<V<<endl;
   cout<<V<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        map<string, int> idx;
        vector<int> t(N);
        for(int i=0;i<N;i++){
            string s; cin >> s >> t[i];
            idx[s] = i;
        }
        string name; cin >> name;
        int res = 0;
        for(int i=idx[name]+1;i<N;i++) res += t[i];
        cout << res << endl;
    }
}

Measured memory_bytes: 256
from collections import defaultdict

d = defaultdict(lambda: 0)
N = int(input())
max = 0
for _ in range(N):
    word = input()
    new_value = d[word] + 1
    if new_value > max:
        max = new_value
    d[word] = new_value

result = []
for key in d:
    if d[key] == max:
        result.append(key)

result.sort()
for a in result:
    print(a)


Measured memory_bytes: 32480
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_M 255

int n;
char matrix[MAX_M][MAX_M + 2];

int
solve()
{
	int max = 0;
	for (int y = 0; y < n; ++y)
	{
		int count = 0;
		for (int x = 0; x < n; ++x)
		{
			if (matrix[y][x] != '1')
			{
				if (count > max)
					max = count;

				count = 0;
			}
			else
				count++;
		}

		if (count > max)
			max = count;
	}

	for (int x = 0; x < n; ++x)
	{
		int count = 0;
		for (int y = 0; y < n; ++y)
		{
			if (matrix[y][x] != '1')
			{
				if (count > max)
					max = count;

				count = 0;
			}
			else
				count++;
		}

		if (count > max)
			max = count;
	}

	for (int i = -(n - 1); i < n; ++i)
	{
		int count = 0;
		int x = i;
		for (int y = 0; y < n; ++x, ++y)
		{
			if (x >= n)
				break;

			if (0 <= x)
			{
				if (matrix[y][x] != '1')
				{
					if (count > max)
						max = count;

					count = 0;
				}
				else
					count++;
			}
		}

		if (count > max)
			max = count;

		count = 0;
		int y = i;
		for (int x = n - 1; x >= 0; --x, ++y)
		{
			if (y >= n)
				break;

			if (0 <= y)
			{
				if (matrix[y][x] != '1')
				{
					if (count > max)
						max = count;

					count = 0;
				}
				else
				count++;
			}
		}

		if (count > max)
			max = count;
	}

	return max;
}

int
main(int argc, char **argv)
{
	while (true)
	{
		scanf("%d\n", &n);
		if (n == 0)
			break;

		for (int i = 0; i < n; ++i)
			fgets(&matrix[i][0], sizeof(matrix[0]), stdin);

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

	return 0;
}

Measured memory_bytes: 1816
#include <cctype>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(i,x,y) for (int i=x; i<=y; ++i)
#define repd(i,x,y) for (int i=x; i>=y; --i)
 
int get()
{
    char c;
    while (!isdigit(c=getchar()));
    int k=c-'0';
    for (; isdigit(c=getchar()); k=k*10+c-'0');
    return k;
}
 
using namespace std;
const int N=3010,mod=1e9+7;
char s[N];
int n,m,ans,c[N][N],l[N],r[N],lb[N],rb[N],f[N][N],a[N];
 
int main()
{
    n=get(),m=get();
    rep(i,0,n)
    {
        c[i][0]=1;
        rep(j,1,i)
            c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
    }
    scanf("%s",s+1);
    rep(i,1,n)
        a[i]=a[i-1]+s[i]-48;
    int t=0;
    rep(i,1,m)
    {
        int x=get(),y=get();
        if (x==l[t])
            r[t]=max(r[t],y);
        else if (y>r[t])
            ++t,l[t]=x,r[t]=y;
    }
    m=t,l[m+1]=n+1,f[0][0]=1;
    rep(i,1,m)
    {
        int w=a[r[i]]-a[max(l[i]-1,r[i-1])];
        int s=min(r[i],l[i+1]-1)-l[i]+1;
        int mx=r[i]-l[i]+1-s;
        lb[i]=max(0,lb[i-1]+w-s),rb[i]=min(mx,rb[i-1]+w);
        rep(j,lb[i],rb[i])
            rep(k,max(j-w,lb[i-1]),min(s+j-w,rb[i-1]))
                f[i][j]=(f[i][j]+1ll*f[i-1][k]*c[s][k+w-j])%mod;
    }
    rep(i,lb[m],rb[m])
        ans=(ans+f[m][i])%mod;
    printf("%d",ans);
    return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;


const ll maxn=2505;
vector<vll> G(maxn);
bool visited[maxn];
void dfs(ll v){
  if(visited[v]) return;
  visited[v]=true;
  for(auto nv: G[v]){
    dfs(nv);
  }
}

vector<vll> rG(maxn);
bool rvisited[maxn];
void rdfs(ll v){
  if(rvisited[v]) return;
  rvisited[v]=true;
  for(auto nv: rG[v]){
    rdfs(nv);
  }
}

ll n,m;
vector<tuple<ll,ll,ll>> es;
ll dist[maxn];
bool ok[maxn];

bool bellmanford(ll s){
  fill(dist,dist+n,INF);
  dist[0]=0;
  bool update=true;
  ll cnt=0;
  while(update){
    update=false;
    for(auto e: es){
      ll a,b,c;
      tie(a,b,c)=e;
      if(!ok[a]||!ok[b]) continue;
      if(chmin(dist[b],dist[a]+c)) update=true;
    }
    if(cnt>=n){
      return true; // has negative loop
    }
    cnt++;
  }
  return false;
}


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll p;
  cin>>n>>m>>p;
  rep(i,m){
    ll a,b,c; cin>>a>>b>>c;
    a--,b--; c=-(c-p);
    es.emplace_back(a,b,c);
    G[a].push_back(b);
    rG[b].push_back(a);
  }
  dfs(0);
  rdfs(n-1);
  rep(i,n) ok[i]=visited[i]&&rvisited[i];
  
  if(!bellmanford(0)){
    ll ans=-dist[n-1];
    if(ans>0) cout<<ans<<endl;
    else cout<<0<<endl;
  }else{
    puts("-1");
  }
  
}

Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
#define LL long long
#define MAXN 500000
#define MOD 998244353
int n,m,F,ans;
int fac[MAXN+5],inv[MAXN+5],pn[MAXN+5],pm[MAXN+5];
LL read(){
   	LL x=0,F=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
   	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*F;
}
int fst_pow(int a,int b){
	int res=1;
	while(b){
		if(b&1)res=1LL*res*a%MOD;
		a=1LL*a*a%MOD;
		b>>=1;
	}return res;
}
void prepare(){
	fac[0]=1;
	for(int i=1;i<=n;i++)
	fac[i]=1LL*fac[i-1]*i%MOD;
	inv[n]=fst_pow(fac[n],MOD-2);
	for(int i=n-1;i>=0;i--)
	inv[i]=1LL*inv[i+1]*(i+1)%MOD;
	pn[0]=1;for(int i=1;i<=n;i++)pn[i]=1LL*pn[i-1]*(n+1)%MOD;
	pm[0]=1;for(int i=1;i<=n;i++)pm[i]=1LL*pm[i-1]*(m+1)%MOD;
}
int Comb(int a,int b){
	return 1LL*fac[a]*inv[b]%MOD*inv[a-b]%MOD;
}
int main()
{
	//freopen("gird.in","r",stdin);
	//freopen("gird.out","w",stdout);
	n=read(),m=read();
	if(n<m)swap(n,m);
	prepare();F=1;
	for(int i=0;i<=m;i++){
		int tmp=F*(1LL*Comb(n,i)*Comb(m,i)%MOD*pn[m-i]%MOD*pm[n-i]%MOD*fac[i]%MOD)%MOD;
		ans=(ans+(tmp+MOD)%MOD)%MOD;
		F*=-1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 8064
//love @Asibuto_Penta
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
string S1,S2;
//red 0 blue 1 green 2 
ll dp1[55][5][5];
ll dp2[55][5];
ll which[55];
ll ans;
ll add(ll x,ll y){
	x=(x+y)%mod;
	return x;
}

int main(){

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

cin>>N>>S1>>S2;

ll i=0,in=0;
while(1){
	if(S1[i]!=S2[i]){
		which[in]=0; i+=2; in++;
	}else{
		which[in]=1; i++; in++;
	}
	if(i>=N) break;
}

if(which[0]==0){
	dp1[0][0][1]=1; dp1[0][1][0]=1;
	dp1[0][1][2]=1; dp1[0][2][1]=1;
	dp1[0][0][2]=1; dp1[0][2][0]=1;
}else{
	dp2[0][0]=1;
	dp2[0][1]=1;
	dp2[0][2]=1;
}

rep1(i,in){
	if(which[i]==0){
		if(which[i-1]==0){
			//add(dp1[i][c1][c2],dp1[i-1][c3][c4]);
			rep(c1,3){
				rep(c2,3){
					rep(c3,3){
						rep(c4,3){
							if(c1==c2) continue;
							if(c3==c4) continue;
							if(c1!=c3&&c2!=c4) dp1[i][c1][c2]=add(dp1[i][c1][c2],dp1[i-1][c3][c4]);
						}
					}
				}
			}
		}else{
			//add(dp1[i][c1][c2],dp2[i-1][c3])
			rep(c1,3){
				rep(c2,3){
					rep(c3,3){
						if(c1==c2) continue;
						if(c1!=c3&&c2!=c3) dp1[i][c1][c2]=add(dp1[i][c1][c2],dp2[i-1][c3]);
					}
				}
			}
		}
	}else{
		if(which[i-1]==0){
			//add(dp2[i][c1],dp1[i-1][c2][c3]);
			rep(c1,3){
				rep(c2,3){
					rep(c3,3){
						if(c2==c3) continue;
						if(c1!=c2&&c1!=c3) dp2[i][c1]=add(dp2[i][c1],dp1[i-1][c2][c3]);						
					}
				}
			}
		}else{
			//add(dp2[i][c1],dp2[i-1][c2])
			rep(c1,3){
				rep(c2,3){
					if(c1==c2) continue;
					dp2[i][c1]=add(dp2[i][c1],dp2[i-1][c2]);
				}
			}
		}
	}
}

if(which[in-1]==0){
	rep(c1,3){
		rep(c2,3){
			ans=add(ans,dp1[in-1][c1][c2]);
		}
	}
}else{
	rep(c1,3){
		ans=add(ans,dp2[in-1][c1]);
	}
}

cout<<ans<<endl;

}
	


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi x(n);
	rep(i, n) cin >> x[i];
	int ans = 1e9;
	repn(i, 1, 101){
		int cur = 0;
		rep(j, n) cur += sq(x[j] - i);
		ans = min(ans, cur);
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
n,a,b = list(map(int,input().split()))
mod = 10**9 + 7
ans = pow(2,n,mod) - 1
numerator = 1
denominator = 1

for i in range(1,n+1):
    numerator = (numerator*(n-i+1))%mod
    denominator = (denominator*i)%mod
    if i == a or i == b:
        ans = ans - (numerator*pow(denominator,mod-2,mod))%mod
        if i == b:
            break

print(ans%mod)

Measured memory_bytes: 3064
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

string S = "";
string T = "";

int main() {
	cin >> S >> T;
	string ans = T + S;
	cout << ans << " ";
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 998244353;
const ld PI = acosl(-1);

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    vector<vector<ll>> dp(C + 3, vector<ll>(D + 3));
    dp[A][B] = 1;
    for (int i = A; i <= C; ++i) {
        for (int j = B; j <= D; ++j) {
            (dp[i + 1][j] += (dp[i][j] * j) % MOD) %= MOD;
            (dp[i][j + 1] += (dp[i][j] * i) % MOD) %= MOD;
            (dp[i + 1][j + 1] -= (dp[i][j] * i % MOD) * j % MOD) %= MOD;
        }
    }

    if (dp[C][D] < 0)
        dp[C][D] += MOD;
    cout << dp[C][D] << endl;

    return 0;
}


Measured memory_bytes: 73684
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip> // 文字幅の指定 setw(int), 詰めたい文字の指定 setfill(char)
#include <algorithm> // sort
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define p(x) cout << (x) << endl
#define FOR(i,r,n) for(ll i=(ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n); i>=r; i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) REP(i,0,n)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pb push_back

// 定義する？→左揃えで0埋め
// cout << setfill('0') << left << setw(4) << 12; // "0012"
// http://marycore.jp/prog/cpp/padding-left-right-zero/

const int inf = (int)1e9;
const ll INF = (ll)1e18;

// vectorの中身をcout << vs;で表示
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
    o << "{";
    for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
    o << "}";
    return o;
}

ll gcd (ll a, ll b) {
	while (b > 0) {
		ll t = a % b;
		a = b, b = t;
	}
	return a;
}

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

bool is_prime (ll n) {
		if (n < 2) return false;
		else if (n == 2) return true;
		else if (n % 2) return false;
		
		double sqrtn = sqrt(n);
		for (ll i = 3; i < sqrtn; i += 2) {
			if (n % i == 0) return false; 
		}
		return true;
}

ll ctoi(char c) {
	return (ll)(c - 48);
}

ll n, k, cnt=0, ans=0;
string s,t;

// ==================== template ============================

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

	int h, w; cin >> n >> h >> w;
	cout << (n-h+1)*(n-w+1) << endl;

}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int H, W;
int main(int argc, char const *argv[])
{
    cin >> H >> W;
    vector<string> S(H);
    for (size_t i = 0; i < S.size(); i++)
    {
        cin >> S[i];
    }
    for (size_t col = 0; col < S.size(); col++)
    {
        for (size_t row = 0; row < S[col].size(); row++)
        {
            if (S[col][row] == '.')
            {
                int ans = 0;
                for (int i = -1; i <= 1; i++)
                {
                    for (int j = -1; j <= 1; j++)
                    {
                        if (0 <= col + i && col + i < S.size() && 0 <= row + j && row + j < S[col].size())
                        {
                            if (S[col + i][row + j] == '#')
                            {
                                ans++;
                            }
                        }
                    }
                }
                S[col][row] = '0'+ans;
            }
        }
    }
    for (size_t col = 0; col < S.size(); col++)
    {
        for (size_t row = 0; row < S[col].size(); row++)
        {
            cout << S[col][row];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256