akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
const int N = 1000;
int blocked[2 * (3 * N + 3)][2 * (3 * N + 3)];
int vis[2 * (3 * N + 3)][2 * (3 * N + 3)];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> hori_x1(n), hori_x2(n), hori_y(n);
    vector<int> vert_y1(m), vert_y2(m), vert_x(m);
    for(int i = 0; i < n; i++) {
        cin >> hori_x1[i] >> hori_x2[i] >> hori_y[i];
    }
    for(int i = 0; i < m; i++) {
        cin >> vert_x[i] >> vert_y1[i] >> vert_y2[i];
    }
    int INF = 1'000'000'000 + 1;
    vector<int> xs = {-INF, 0, INF}, ys = {-INF, 0, INF};
    for(auto& v : {hori_x1, hori_x2, vert_x}) {
        for(int x : v) {
            xs.push_back(x);
        }
    }
    for(auto& v : {vert_y1, vert_y2, hori_y}) {
        for(int y : v) {
            ys.push_back(y);
        }
    }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    sort(ys.begin(), ys.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());
    auto comp = [](int coord, const vector<int>& s) { return lower_bound(s.begin(), s.end(), coord) - s.begin(); };
    for(int i = 0; i < n; i++) {
        int x1 = comp(hori_x1[i], xs), x2 = comp(hori_x2[i], xs), y = comp(hori_y[i], ys);
        for(int c = x1; c < x2; c++) {
            blocked[2 * c][2 * y] = 1;
            blocked[2 * c + 1][2 * y] = 1;
        }
        blocked[2 * x2][2 * y] = 1;
    }
    for(int i = 0; i < m; i++) {
        int y1 = comp(vert_y1[i], ys), y2 = comp(vert_y2[i], ys), x = comp(vert_x[i], xs);
        for(int c = y1; c < y2; c++) {
            blocked[2 * x][2 * c] = 1;
            blocked[2 * x][2 * c + 1] = 1;
        }
        blocked[2 * x][2 * y2] = 1;
    }
    queue<pair<int, int>> q;
    q.push({2 * comp(0, xs), 2 * comp(0, ys)});
    vis[q.front().first][q.front().second] = true;
    int di[] = {-1, 1, 0, 0};
    int dj[] = {0, 0, -1, 1};
    ll ans = 0;
    while(not q.empty()) {
        auto [i, j] = q.front(); q.pop();
        ans += ll(xs[(i + 1) / 2] - xs[i / 2]) * ll(ys[(j + 1) / 2] - ys[j / 2]);
        for(int d = 0; d < 4; d++) {
            int ni = i + di[d];
            int nj = j + dj[d];
            if(0 <= ni and ni < 2 * xs.size() and 0 <= nj and nj < 2 * ys.size() and not blocked[ni][nj] and not vis[ni][nj]) {
                q.push({ni, nj});
                vis[ni][nj] = true;
            }
        }
    }
    if(vis[2 * comp(INF, xs)][2 * comp(INF, ys)]) {
        cout << "INF" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 237048
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> A(N+1);
    vector<long long> B(N);
    
    for(int i=0;i<=N;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++){
        cin >> B[i];
    }

    long long ans = 0;
    for(int i=0;i<N;i++){
        if(A[i]>=B[i]){
            ans += B[i];
        }else{
            if(B[i]-A[i]<=A[i+1]){
                ans += B[i];
                A[i+1] -= B[i]-A[i];
            }else{
                ans += A[i]+A[i+1];
                A[i+1] = 0;
            }
        }
        }
    cout << ans << endl;
    
    return 0;
}


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

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

int main() {

    int n;cin >> n;
    int ans = 0;
    if (n%2 == 0) {
        ans = n/2 -1;
    } else {
        ans = n/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
main :: IO ()
main = do
    array <- readLn >>= input
    putStrLn $ (++) "AC x " $ show (count "AC" array)
    putStrLn $ (++) "WA x " $ show (count "WA" array)
    putStrLn $ (++) "TLE x " $ show (count "TLE" array)
    putStrLn $ (++) "RE x " $ show (count "RE" array)

input :: Int -> IO [String]
input 0 = pure [] :: IO [String]
input n = (:) <$> getLine <*> input (n-1)

count :: (Ord a) => a -> [a] -> Int
count _ [] = 0
count n (x:xs)
    | n == x    = 1 + count n xs
    | otherwise = count n xs 


Measured memory_bytes: 36436
#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;

#define rep(i,j) for(int i=0;i<(j);i++)
#define INF (1<<29)

typedef pair<int,int>P;

struct edge{
  int to,cost;
  edge(int to, int cost):to(to),cost(cost){}
};

int N,M,K;
vector<edge>G[3005];
int A[100005],B[100005],L[100005];
int s[3005];
int dist[3005];

void dijkstra(){
  fill(dist, dist+N, INF);
  priority_queue<P, vector<P>, greater<P> >q;
  rep(i,K){
    dist[s[i]] = 0;
    q.push(P(0, s[i]));
  }

  while(!q.empty()){
    P p = q.top(); q.pop();
    int v = p.second;
    if(dist[v] < p.first) continue;
    rep(i,G[v].size()){
      edge e = G[v][i];
      if(dist[e.to] > dist[v] + e.cost){
	dist[e.to] = dist[v] + e.cost;
	q.push(P(dist[e.to], e.to));
      }
    }
  }
}

int main(){
  scanf("%d%d%d", &N,&M,&K);
  rep(i,M){
    int a,b,l;
    scanf("%d%d%d", &a,&b,&l); a--; b--;
    G[a].push_back(edge(b,l));
    G[b].push_back(edge(a,l));
    A[i] = a; B[i] = b; L[i] = l;
  }

  rep(i,K){
    scanf("%d", s+i);
    s[i]--;
  }
  dijkstra();
  int res = 0;
  rep(i,N) res = max(res, dist[i]);
  rep(i,M) res = max(res, (dist[A[i]]+dist[B[i]]+L[i]+1)/2);
    
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 5204
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        int[] a = new int[n+1];
        for(int i=0;i<n+1;i++){
            a[i] = fs.nextInt();
        }
        int[] b = new int[n];
        for(int i=0;i<n;i++)b[i] = fs.nextInt();

        long sum = 0;
        long remain = 0,beat;
        for(int i=n-1;i>=0;i--){
            remain = b[i];
            sum+=Math.min(remain,a[i+1]);
            remain-=a[i+1];
            if(remain>0){
                beat = Math.min(remain,a[i]);
                a[i]-=beat;
                sum+=beat;
            }
        }

        System.out.println(sum);

    }
    static class FastScanner{
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte(){
            if(ptr < buflen){
                return true;
            }else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen <= 0){
                    return false;
                }
            }
            return true;
        }

        private int readByte(){
            if(hasNextByte())return buffer[ptr++];
            else return -1;
        }

        private boolean isPrintableChar(int c){
            return 33<=c && c<=126;
        }

        public boolean hasNext(){
            while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
            return hasNextByte();
        }

        public String next(){
            if(!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)){
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong(){
            if(!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if(b == '-'){
                minus = true;
                b = readByte();
            }
            if(b < '0' || '9' < b){
                throw new NumberFormatException();
            }
            while(true){
                if('0' <= b && b<='9'){
                    n*=10;
                    n+=b-'0';
                }else if(b==-1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt(){
            long nl = nextLong();
            if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
            return (int)nl;
        }
        public double nextDouble(){return Double.parseDouble(next());}
    }
}

Measured memory_bytes: 23508
##かっこいい実装
import numpy as np
#mod = 10**9+7
#n = int(input())
#a = np.fromstring(input(), dtype = np.int64, sep = ' ')
#
#result = 0
#for i in range(60):
#    count_one = int((a&1).sum())
#    result += count_one*(n-count_one)*(2**i)
#    a >>= 1
#print(result%mod)

N = int(input())
A = np.fromstring(input(),dtype = np.int64, sep = ' ')
Large = 10**9 + 7
ans = 0
for i in range(60):
    sum1 = int((A&1).sum())
    ans += sum1*(N-sum1) * 2**i
    #ans %= Large
    A>>=1 # A = A>>1とする
print(ans%Large)








Measured memory_bytes: 28844
import java.io.*;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int ans = Math.min(Math.min(A+B, B+C),C+A);
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <queue>
#define ll long long 
#define ri register int 
using std::min;
using std::max;
template <class T>inline void read(T &x){
    x=0;int ne=0;char c;
    while(!isdigit(c=getchar()))ne=c=='-';
    x=c-48;
    while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
    x=ne?-x:x;return ;
}
const int maxn=305;
const int inf=0x7fffffff;
int a[maxn][maxn];
int n,m;
bool ok[maxn];
int cnt[maxn],ans=inf;
int main(){
    int mx,p;
    read(n),read(m);
    for(ri i=1;i<=n;i++){
        for(ri j=1;j<=m;j++){
            read(a[i][j]);
        }
    }
    for(ri k=1;k<=m;k++){
    	memset(cnt,0,sizeof(cnt));
        for(ri i=1;i<=n;i++){
            for(ri j=1;j<=m;j++){
                if(!ok[a[i][j]]){
					cnt[a[i][j]]++;
					break;
				}
            }
        }
        mx=0,p=0;
        for(ri i=1;i<=m;i++){
            if(cnt[i]>mx)mx=cnt[i],p=i;
        }
        ok[p]=1;
        ans=min(ans,mx);
    }
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;

#define ll long long

//#define TEST

vector<vector<int>> g(300);

// logic[i][j] := ?「iならばj」
int logic[300][300];

vector<int> visited(300);
int start;
void dfs(int s) {
	visited[s] = 1;
	for (auto t : g[s]) {
		if (!(visited[t])) {
			visited[t] = 1;
			logic[start][t] = 1;
			dfs(t);
		}
	}
}

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

	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].push_back(b);
	}

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			logic[i][j] = 0;
	for (int i = 0; i < n; ++i)
		logic[i][i] = 1;

	for (int i = 0; i < n; ++i) {
		start = i;
		for (int j = 0; j < n; ++j)
			visited[j] = 0;
		dfs(start);
	}

#ifdef TEST
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j)
			cout << logic[i][j] << " ";
		cout << endl;
	}
#endif

	for (int i = 0; i < n; ++i) {
		vector<int> ans;
		for (int j = 0; j < n; ++j)
			if (logic[i][j] && logic[j][i])
				ans.push_back(j + 1);
		for (int j = 0; j < ans.size() - 1; ++j)
			cout << ans[j] << " ";
		cout << ans[ans.size() - 1] << endl;
	}

	return 0;
}


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

int H,W;
int cost[11][11];
int num[205][205];
int memory[11];

void floyd(){
	for(int k=0;k<10;k++)
 		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)
				if(cost[i][j]>(cost[i][k]+cost[k][j]))
             	{
                   		cost[i][j]=cost[i][k]+cost[k][j];
                   //path[i][j]=k;
               } 
}

int main(){
	cin>>H>>W;
	int temp;
	int sum = 0;
	
//	for(int i=0; i<10; i++){
//		memory[i] = -1;
//	}
//	
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			cin >> cost[i][j];
		}
	}
	
	floyd();
	
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			cin >> temp;
			if(temp == -1||temp == 1) continue;
//			if(memory[temp]!= -1){
//				sum += memory[temp];
//				continue;
//			}
//			int itcost = calcu(temp);
			sum += cost[temp][1];
//			memory[temp] = itcost;			
		}
	}
	cout << sum << endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;                                                   
int main(){
  int N,K;
  int amari;
  cin >> N >> K;
  amari = N % K;
  if(amari != 0){
   cout << 1 << endl;
  }else{
   cout << 0 << endl;
  }
 }


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

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

	int n;
	cin >> n;
	n %= 10;

	switch (n) {
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
			cout << "hon\n";
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			cout << "pon\n";
			break;
		default:
			cout << "bon\n";
			break;
	}

}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll  long long int
#define fr(i,n) for(ll i=0; i<n; i++)
#define fre(i,n) for(ll i=1; i<=n; i++)
#define pb push_back
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define pii pair<ll,ll>
#define ve vector
#define piii pair<pii, ll>
#define FAST ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;


int main()
{  
    FAST;
    long long int n,w,v, W;
    cin>>n>>W;

    long long int a[n+1][W+1];

    memset(a, 0, sizeof(a));

    for(long long  int k=1; k<=n;  k++){
        cin>>w>>v;

        for(long long  int i=1; i<=W; i++){
            if(w>i)
                a[k][i] = a[k-1][i];
            else
                a[k][i] = max(a[k-1][i] , v+a[k-1][i-w]);
        }
    }

    cout<<a[n][W]<<endl;


}


Measured memory_bytes: 79232
import itertools
list = [int(input()) for _ in range(5)]
temp = 0
ans = 10**9

for v in itertools.permutations(list):
    temp = 0
    for i,j in enumerate(v):
        if i != 4:
            if j % 10 == 0:
                temp += j
            else:
                temp += (j//10+1)*10
        else:
            temp += j
    ans = min(ans,temp)

print(ans)

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

def solve():
    N = int(input())
    ans = 0
    for i in range(1, N+1):
        if i%15 == 0:
            continue
        elif i%3 == 0:
            continue
        elif i%5 == 0:
            continue
        ans += i
    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 9164
fun main(args: Array<String>) {
  val (N,M) = readLine()!!.split(" ").map{it.toInt()}
  var m = (1..M).map{it}.toSet()
  val k = (1..N).map{
    readLine()!!.split(" ").map{it.toInt()}.drop(1)
  }
  for(i in 0 until N) {
    m = m.intersect(k.get(i))    
  }
  println(m.size)
}

Measured memory_bytes: 36004
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define Pi 3.1415926535
#define MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}

int solve(){
    string s; cin >> s;
    if(s[2] == s[3] and s[4] == s[5]){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;

    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 764
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

sorted_a = sorted(a)
first = sorted_a[-1]
second = sorted_a[-2]
first_place = a.index(first)
for i in range(n):
    if first == second:
        print(first)
    else:
        if i == first_place:
            print(second)
        else:
            print(first)


Measured memory_bytes: 14112
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

bool equal(vector<ll> v1, vector<ll> v2){
  if(v1.size() != v2.size()) return false;
  rep(i, (ll) v1.size())
    if(v1[i] != v2[i]) return false;
  return true;
}

int main(){
  string S, T;
  cin >> S >> T;

  string ans = "Yes";
  for(char alp = 'a'; alp <= 'z'; ++alp){
    vector<ll> sidx, tidx;
    rep(i, (ll) S.size())
      if(S[i] == alp) sidx.push_back(i);
    if(sidx.size() <= 0) continue;
    char tch = T[sidx[0]];
    rep(i, (ll) S.size())
      if(T[i] == tch) tidx.push_back(i);
    if(!equal(sidx, tidx)){
      ans = "No";
      break;
    }
  }

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


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

vector<long long> divisors(long long n) {
  vector<long long> res;
  for (int i = 1; i < int(sqrt(n)) + 1; i++) {
    if (n % i == 0) res.push_back(i);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  auto res = divisors(n);
  int ans = to_string(n /res[res.size() - 1]).size();
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
s = list(input())

bangou = 0
seikou = True
for moji in s:
    bangou += 1
    if bangou % 2 == 0:
        if moji in ["L", "U", "D"]:
            continue
        else:
            seikou = False
            break
    else:
        if moji in ["R", "U", "D"]:
            continue
        else:
            seikou = False
            break
if seikou:
    print("Yes")
else:
    print("No")

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

int main(){
  string s;
  getline(cin, s);

  for(int i = 0; i < s.size(); i++){
    if(s[i] >= 'a' && s[i] <= 'z'){
      s[i] -= 32;
    }
    else if(s[i] >= 'A' && s[i] <= 'Z'){
      s[i] += 32;
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;


int N;
map<int, int> M;
vector<int> P = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};

void fact(int i){
    for(int p:P){
        while(i%p==0){
            M[p]++;
            i /= p;
        }
    }
    return;
}



int main() {
    cin >> N;
    for(int i=1; i<=N; i++){
        fact(i);
    }
    
    int c4 = 0;
    int c2 = 0;
    int c14 = 0;
    int c24 = 0;
    int c74 = 0;
    for(auto m:M){
        if(m.second >= 4) c4++;
        if(m.second >= 2) c2++;
        if(m.second >= 14) c14++;
        if(m.second >= 24) c24++;
        if(m.second >= 74) c74++;
    }
    int ans = c74;
    ans += (c4-1)*c14;
    ans += (c2-1)*c24;
    
    
    if(c4<2 || c2<1){
        cout << 0 << endl;
        return 0;
    }
    
    c2 -= 2;
    ans += c4*(c4-1)/2*c2;

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






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

int INF = 1000000000 ;

void bfs(vector<vector<int>> &g,vector<int> &cnt,queue<int> &q,int pos){
	int n = cnt.at(pos) ;
	for(int i=0;i<g.at(pos).size();i++){
		if(cnt.at(g.at(pos).at(i))>n+1){
			cnt.at(g.at(pos).at(i)) = n+1 ;
			q.push(g.at(pos).at(i)) ;
		}
	}
	if(q.empty()) return ;
	pos = q.front() ; q.pop() ;
	bfs(g,cnt,q,pos) ;
}

int main(){
	int n,m ;
	cin >> n >> m ;
	vector<vector<int>> g(n,vector<int>(0)) ;
	for(int i=0;i<m;i++){
		int a,b ;
		cin >> a >> b ;
		a-- ; b-- ;
		g.at(a).push_back(b) ;
		g.at(b).push_back(a) ;
	}
	queue<int> q ;
	vector<int> cnt(n,INF) ;
	cnt.at(0) = 0 ;
	bfs(g,cnt,q,0) ;
	if(cnt.at(n-1)>2) cout << "IMPOSSIBLE" << endl ;
	else cout << "POSSIBLE" << endl ;
}


Measured memory_bytes: 13168
//Radhe Radhe
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//using namespace boost::multiprecision;
//#include<boost/math/common_factor.hpp>
#include <ext/numeric>
using namespace __gnu_cxx;
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define array(a,n) int a[n]; for(int i=0;i<n;i++) cin>>a[i];
#define loop(i,a,b,x) for(int i=a;i<b;i+=x)
const int MOD = 1000000007;
const int N = 10001;




int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        int a[n];
        for (int i = 0; i < n; i++)
            cin >> a[i];
        bool dp[k + 1] = {false};
        for (int i = 1; i <= k; i++) {
            for (int j = 0; j < n; j++) {
                if (i - a[j] < 0)
                    break;
                else {
                    if (dp[i - a[j]] == false)
                        dp[i] = true;
                }
            }
        }
        if (dp[k])
            cout << "First" << endl;
        else
            cout << "Second" << endl;
    }
    return 0;

}



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

template<typename T1,typename T2> void chmin(T1 &a,T2 b){if(a>b) a=b;};
template<typename T1,typename T2> void chmax(T1 &a,T2 b){if(a<b) a=b;};

Int c[111][111];
signed main(){
  Int n;
  cin>>n;
  for(Int i=0;i<n;i++)
    for(Int j=0;j<n;j++)
      cin>>c[i][j];
  
  Int ans=0;
  for(Int i=0;i<n;i++)
    for(Int j=0;j<i;j++)
      ans+=min(c[i][j],c[j][i]);

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



Measured memory_bytes: 3184
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
  int n, m, i;
  scanf("%d%d", &n, &m);
  for (i = 1; i < 1250; i++)
  {
    if (((int)(i * 0.08) == n) && ((int)(i * 0.1) == m))
    {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}

Measured memory_bytes: 128
x = int(input())
y = int(input())
z = int(input())
a = int(input())
c = a/50

count = 0
for i in range(0,x+1):
    for j in range(0,y+1):
        for k in range(0,z+1):
            if(((10*i)+(2*j)+(k)) == c):
                count+=1

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
//#define int long long
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>

using namespace std;

signed main(){
  string O, E, X;
  cin >> O >> E;
  X = O + E;
  int l = max(O.length(), E.length());

  if(O.length() == E.length()){
    rep(i, l){
      cout << O[i] << E[i];
    }
  }else{
    rep(i, l - 1){
      cout << O[i] << E[i];
    }
    cout << O[O.length() - 1];
  }
  cout << endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

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

  L = A + B;
  R = C + D;

  if(L > R){
    cout << "Left" << "\n";
  }
  else if(R > L){
    cout << "Right" << "\n";
  }
  else{
    cout << "Balanced" << "\n";
  }
  
  return 0;
}

Measured memory_bytes: 256
def palindrome(S):
  for i in range(len(S)//2):
#    print(S[i],S[-(i+1)])
    if S[i] != S[-(i+1)]:
      return 0
  return 1
ans = "No"
S = input()
S1 = S[:(len(S)-1)//2]
S2 = S[(len(S)+1)//2:]
#print(palindrome(S))
#print(palindrome(S1))
#print(palindrome(S2))

if palindrome(S) == 1:
  if palindrome(S1) == 1:
    if palindrome(S2) == 1:
      ans = "Yes"
print(ans)

Measured memory_bytes: 9120
#include <iostream>
#include <vector>
using i64 = long long;

std::vector<long long> fact, inv;

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

constexpr auto inverse(const long long x, const long long p) {
    return pow(x, p - 2, p);
}

void init_factorial(const int n, const long long mod) {
    fact.resize(n + 1);
    inv.resize(n + 1);
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (long long i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

int main() {
    constexpr i64 mod = 1000000007;
    int n, m;
    std::cin >> n >> m;
    init_factorial(m, mod);

    i64 ret = 0;
    for (int k = 0; k <= n; k++) {
        const i64 w = fact[n] * inv[k] % mod * inv[n - k] % mod * fact[m - k] % mod * inv[m - n] % mod;
        if (k & 1) {
            ret = (ret + mod - w) % mod;
        } else {
            ret = (ret + w) % mod;
        }
    }

    std::cout << ret * fact[m] % mod * inv[m - n] % mod << std::endl;

    return 0;
}


Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N;

int main()
{
    cin >> N;
    vector<double> v(N);
    for (int i = 0; i < N; i++)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    double ave = (v[0] + v[1]) / 2.;
    for (int i = 2; i < N; i++)
    {
        ave = (ave + v[i]) / 2.;
    }
    printf("%lf\n", ave);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int MOD=1e9+7;
int main(){
  int64_t n,k,a=0;
  cin>>n>>k;
  for(int i=k;i<n+2;i++)a=(a+i*(n-i+1)+1)%MOD;
  printf("%d\n",a);
}


Measured memory_bytes: 3756
#include<iostream>
using namespace std;
#define INF (1 << 21);

int main(){
  int N, X[100];
  cin >> N;
  for(int i = 0;i < N;++i)
    cin >> X[i];
  int minv = INF;
  for(int i = 1;i <= 100;++i){
    int sum = 0;
    for(int j = 0;j < N;++j){
      sum += (X[j] - i)*(X[j] - i);
    }
    minv = min(minv, sum);
  }
  cout << minv;
}


Measured memory_bytes: 256
#include<stdio.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long

int main(){
	int n,x,a[100002];
	ll sum1 = 0;
	scanf("%d %d",&n,&x);
	FOR(i,0,n) scanf("%d",&a[i]);

	FOR(i,0,n-1){
		if(a[i]+a[i+1] > x){
			sum1 += a[i] + a[i+1] -x;
			if(a[i] - x < 0) a[i+1] = x - a[i];
			else{
				a[i+1] = 0;
				a[i] = x;
			}
		}
	}

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

Measured memory_bytes: 512
import java.util.*;
import java.math.*;

public class Main {

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

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }

    Arrays.sort(a);

    for (int i = 0; i < n-1; i++) {
      if (a[i] == a[i+1]) {
        System.out.println("NO");
        return;
      }
    }

    System.out.println("YES");
    
  }

}


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

int main(){
    string s;
    cin >> s;
    ll n = s.size();
    ll ans = 1e18;
    for(char c = 'a'; c <= 'z'; c++){
        string t = s;
        bool f = false;
        for(auto e : t) if(e == c) f = true;
        if(!f) continue;
        ll cnt = 0;
        while(true){
            bool f = true;
            for(auto e : t) if(e != c) f = false;
            if(f) break;
            string next(t.size()-1, 'a');
            for(int i = 0; i < t.size()-1; i++){
                if(t[i] == c || t[i+1] == c) next[i] = c;
                else next[i] = t[i];
            }
            cnt++;
            t = next;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
// Author : Mahmoud Tarek

#include <bits/stdc++.h>

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define debug(x , y) cerr << #x << " = " << x << y ;

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}


int n ;
double a ;
double sum ;

int main(){
 cin >> n ;
 while( n-- ){
    cin >> a ;
    sum += 1 / a ;
 }
 cout << fixed << setprecision( 5 ) << ( 1 / sum ) ;
 return 0 ;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	ll cost=0;
	ll N,A,B;
	cin>>N>>A>>B;
	vector<ll> X(N);
	for(int i=0;i<N;i++) cin>>X[i];
	for(int i=0;i<N-1;i++){
		ll dist=X[i+1]-X[i];
		if(dist*A>B) cost+=B;
		else cost+=(A*dist);
	}
	cout<<cost<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  for(int i=0; i<n; i++) {
    cin >> a[i] >> b[i];
  }
  vector<pair<int, int>> AB(n);
  for(int i=0; i<n; i++){
    AB[i] = make_pair(a[i], b[i]);
  }
  sort(AB.begin(), AB.end());
  ll ans = 0;
  for(int i=0; i<n; i++){
    int buy = min(m, AB[i].second);
    ans += (ll)buy * AB[i].first;
    m -= buy;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,m,q;
ll a[100005],t[100005],k,ans[100005];
int main(){
    scanf("%d%d",&n,&m);
    a[q=1]=n;
    for(int i=1;i<=m;++i){
        ll x;
        scanf("%lld",&x);
        while(a[q]>=x&&q)--q;
        a[++q]=x;
    }
    t[q]=1;
    for(int i=q;i>1;--i){
        t[i-1]+=t[i]*(a[i]/a[i-1]);
        k=a[i]%a[i-1];
        int o;
        do{
            o=0;
            for(int j=16;j>=0;--j){
                int _=o+(1<<j);
                if(_<i&&a[_]<=k)o=_;
            }
            if(!o)ans[k]+=t[i];
            else t[o]+=(k/a[o])*t[i],k%=a[o];
        }while(o);
    }
    ans[a[1]]+=t[1];
    for(int i=n-1;i;--i)ans[i]+=ans[i+1];
    for(int i=1;i<=n;++i)printf("%lld\n",ans[i]);
    //system("pause");
    return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
	unsigned long int X, Y;
	cin >> X;
	cin >> Y;

	int i = 0;
	unsigned long int max = X;
	
	while( max <= Y ){
		max *= 2;
		i++;
	}
	
	/*
	これはなぜか落ちる
	unsigned long int ans = ( log2(Y)-log2(X) ) + 1;
	*/
	
	cout << i << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int h1,m1,h2,m2,k;
int main()
{
	scanf("%d%d%d%d%d",&h1,&m1,&h2,&m2,&k);
	int ansh=h2-h1,ansm=m2-m1;
	if(ansm<0) ansm+=60,ansh--;
	if(ansh<0) ansh+=24;
	int t=ansh*60+ansm;
	t-=k;
	printf("%d",max(t,0));
	return 0;
}

Measured memory_bytes: 3836
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 100000000

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}
//A  
bool fflag,sflag;
void solve(void){
    int a,b,c;
   cin >> a >> b>>c;
 
   if((a == 5 && b == 5)||(a == 5 && c == 5)||(c == 5 && b == 5)) fflag = true;
    if(a == 7 || b == 7 || c == 7) sflag = true;
    if(fflag&&sflag) yb();
    else nb();
}


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

Measured memory_bytes: 256
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val Array(n, x) = in.readLine.split(" ").map(_.toInt)
  val li = in.readLine.split(" ").map(_.toInt)
  val table = Array.ofDim[Int](n+1)
  for(i <- 0 until n) {
    table(i+1) = table(i) + li(i)
  }
  val ans = table.count(_ <= x)
  println(ans)
}

Measured memory_bytes: 27460
import java.util.Scanner;

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

		long Q = sc.nextLong();
		long H = sc.nextLong();
		long S = sc.nextLong();
		long D = sc.nextLong();
		long N = sc.nextLong();

		System.out.println((N/2) * Math.min(Math.min(Math.min(H, Q * 2) * 2,S)*2,D)+(N % 2) * Math.min(Math.min(H, Q * 2) * 2,S));

	}
}


Measured memory_bytes: 35700
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main() {
    cin>>N;
    unordered_map<ll, ll> num;
    ll sum = 0;
    rep(i,N){
        cin>>A;
        ++num[A];
        sum += A;
    }
    cin>>Q;
    rep(_, Q){
        cin>>B>>K;
        ll temp = num[B];
        sum -= temp * B;
        sum += temp * K;
        num[B] -= temp;
        num[K] += temp;
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 6900
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int T, N, S;

int main () {
        scanf("%d", &T);
        while (T--) {
                scanf("%d %d", &N, &S);
                printf("%d\n", (N-1) * 127 + ((N&1) ? S : (127-S)));
        }
        return 0;
}


Measured memory_bytes: 256
import sys

MOD = 10 ** 9 + 7

def make_table(size=10**6, p=MOD):
    fac = [None] * (size + 1)
    fac[0] = 1
    for i in range(size):
        fac[i+1] = fac[i] * (i + 1) % p
    ifac = [None] * (size + 1)
    ifac[size] = pow(fac[size], p-2, p)
    for i in range(size, 0, -1):
        ifac[i-1] = ifac[i] * i % p
    icumsum = [None] * (size + 1)
    icumsum[1] = 1
    for i in range(1, size):
        icumsum[i+1] = (icumsum[i] + fac[i] * ifac[i+1]) % MOD
    return fac, ifac, icumsum

fac, ifac, icumsum = make_table(10**5)

def comb(n, r, mod=MOD):
    if r > n or r < 0:
        return 0
    return fac[n] * ifac[r] % mod * ifac[n-r] % mod

n, *x = map(int, sys.stdin.read().split())

def main():
    d = [x[i+1] - x[i] for i in range(n-1)]

    res = 0
    for i in range(n-1):
        res += d[i] * icumsum[i+1]
        res %= MOD

    return res * fac[n-1] % MOD

if __name__ == '__main__':
    ans = main()
    print(ans)

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

using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = 1000 * 1000 * 1000 + 7;

int main() {
	//freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
	ll n, k, c;
	cin >> n >> c >> k;
	vector<ll> t(n);
	for (int i = 0; i < n; ++i) {
		cin >> t[i];
	}
	sort(t.begin(), t.end());
	int curT = t[0] + k;
	int curC = 1;
	int ans = 1;
	for (int i = 1; i < n; ++i) {
		if (curC < c && t[i] <= curT) {
			++curC;
			continue;
		}
		curC = 1;
		curT = t[i] + k;
		++ans;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
  int n; cin >> n;
  string s, t; cin >> s >> t;
  rep(i, n) cout << s[i] << t[i];
  cout << endl;

  return 0;
}


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

a,b = map(int,input().split())

coin = 0
if a >= b:
    coin += a
    a -= 1
else:
    coin += b
    b -= 1
if a >= b:
    coin += a
    a -= 1
else:
    coin += b
    b -= 1

print(coin)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main() {
	string s, t, u;
	int a, b;
	cin >> s >> t;
	cin >> a >> b;
	cin >> u;
	
	if (u == s) {
		a--;
	}
	else if (u == t) {
		b--;
	}
	
	cout << a << " " << b << endl;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
l_a=list(map(int,input().split()))
l_l=[0]*n#インデ i-1までのgcd
l_r=[0]*n#インデi+1からのgcd
def gcd(a,b):#最大公約数を返す。Euclid
    if a<b:
        a,b=b,a
    if b==0:
        return a
    return gcd(b,a%b)

for i in range(n):
    if i!=0:
        l_l[i]=gcd(l_l[i-1],l_a[i-1])
        l_r[n-1-i]=gcd(l_r[n-i],l_a[n-i])
M=1
for i in range(n):
    m=gcd(l_l[i],l_r[i])
    if m>M:
        M=m
print(M)


#最大公約数→Euclid(log(min(a,b))) ,2数のgcdは簡単に求まる


Measured memory_bytes: 14136
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)

int factorial(int N) {
    int ans = 1;
    for (int i = 2; i <= N; i++) ans = (ll)ans * i % 1000000007;
    return ans;
}

int main() {
    int N, M;
    cin >> N >> M;
    int dif = abs(N - M);
    cout << (ll)factorial(N) * factorial(M) * max(0, (2 - dif)) % 1000000007 << endl;
    return 0;
}

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

using namespace std;
static const int MAX = 10;

int factorial(int n) {
    int f = 1;
    for (int i = 1; i <= n; ++i) f *= i;
    return f;
}

double distance(int x1, int y1, int x2, int y2) {
    int dx = x2 - x1;
    int dy = y2 - y1;
    return pow(dx * dx + dy * dy, 0.5);
}

int main() {
    int N, X[MAX], Y[MAX], R[MAX];
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> X[i];
        cin >> Y[i];
        R[i] = i;
    }

    double D[MAX][MAX];
    for (int i = 0; i < N - 1; ++i) {
        for (int j = i + 1; j < N; ++j) {
            // i - j 間距離 (i > j)
            double d = distance(X[i], Y[i], X[j], Y[j]);
            D[i][j] = d;
        }
    }

    double sum = 0;
    do {
        int prev = R[0];
        for (int j = 1; j < N; ++j) {
            sum += D[min(prev, R[j])][max(prev, R[j])];
        }
    } while (next_permutation(R, R + N));

    cout.precision(10);
    cout << sum / factorial(N) << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
    if i+1 == a[i] and i != n-1:
        b = a[i]
        c = a[i+1]
        a[i] = c
        a[i+1] = b
        ans += 1
    elif i+1 == a[i]:
        ans += 1
print(ans)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
int n,dp[2003][2003],a[6003],ans,tg,MX[2003],cur;
int A[100004],B[100004],C[100004],t;
void init(){t=0;}
void add(int x,int y,int z){A[t]=x,B[t]=y,C[t++]=z;}
int main(){
	cin>>n;
	for(int i=1;i<=3*n;i++)cin>>a[i]; 
	dp[a[1]][a[2]]=dp[a[2]][a[1]]=MX[a[1]]=MX[a[2]]=cur=1;
	for(int i=3;i<3*n;i+=3){
		if(a[i]==a[i+1]&&a[i]==a[i+2]){tg++;continue;}
		init();
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		if(a[i+1]>a[i+2])swap(a[i+1],a[i+2]);
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		for(int j=1;j<=n;j++){
		if(a[i]==a[i+1])if(dp[j][a[i]]>0)add(j,a[i+2],dp[j][a[i]]+1);
		if(a[i+1]==a[i+2])if(dp[j][a[i+1]]>0)add(j,a[i],dp[j][a[i+1]]+1);
		}
		if(dp[a[i]][a[i]]>0)add(a[i+1],a[i+2],dp[a[i]][a[i]]+1);
		if(dp[a[i+1]][a[i+1]]>0)add(a[i],a[i+2],dp[a[i+1]][a[i+1]]+1);
		if(dp[a[i+2]][a[i+2]]>0)add(a[i],a[i+1],dp[a[i+2]][a[i+2]]+1);
		add(a[i],a[i+1],cur),add(a[i+1],a[i+2],cur),add(a[i],a[i+2],cur);
		for(int j=i;j<i+3;j++)for(int k=1;k<=n;k++)if(MX[k]>0)add(a[j],k,MX[k]);
		for(int j=0;j<t;j++)if(dp[A[j]][B[j]]<C[j])
			dp[A[j]][B[j]]=dp[B[j]][A[j]]=C[j],MX[A[j]]=max(MX[A[j]],C[j]),MX[B[j]]=max(MX[B[j]],C[j]),cur=max(cur,C[j]);
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++)if(dp[i][j]>=0)ans=max(ans,dp[i][j]-1);
		if(dp[i][i]>=0)if(i==a[3*n])ans=max(ans,dp[i][i]);
	}
	printf("%d",ans+tg);
}


Measured memory_bytes: 19020
#include<iostream>
//#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
using namespace std;
typedef long long ll;
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll max;
	max=b*d;
	if(max<a*c)
		max=a*c;
	if(max<a*d)
		max=a*d;
	if(max<b*c)
		max=b*c;
	cout << max;
	return 0;
}

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

const int maxn=10;
int n,m,cnt;
char s[maxn];

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		cin>>s;
		for(int j=0;s[j];++j)
			if(s[j]=='#')
				++cnt;
	}
	puts(cnt==n+m-1?"Possible":"Impossible");
	return 0;
}

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

int main()
{
    string s;
    cin>>s;
    long long int n=s.size(),i;
    long long int a[n]={0};
    long long int rpointer,lpointer;
    long long int totalr=0,totall=0;
    long long int t=1;
    for(i=0;i<n;i++)
    {
        if(t&&s[i]=='R')
            totalr++;
        else if(t&&s[i]=='L')
        {
            rpointer=i-1;
            lpointer=i;
            totall++;
            t=0;
        }
        else if(!t&&s[i]=='L')
        {
            totall++;
        }
        else if(!t&&s[i]=='R')
        {
            long long int dif=max(totall,totalr)-min(totall,totalr);
            a[lpointer]=min(totall,totalr);
            a[rpointer]=min(totall,totalr);
            a[lpointer]+=dif/2;
            a[rpointer]+=dif/2;
            dif%=2;
            if(totalr>totall&&dif>0)
                a[rpointer]++;
            else if(totall>totalr&&dif>0)
                a[lpointer]++;
            long long int x=max(totall,totalr)-1;
            if(x%2)
                swap(a[rpointer],a[lpointer]);
            t=1;
            totall=0;
            totalr=1;
        }
    }

   // cout<<totall<<" "<<totalr<<"\n";
            long long int dif=max(totall,totalr)-min(totall,totalr);
            a[lpointer]=min(totall,totalr);
            a[rpointer]=min(totall,totalr);
            a[lpointer]+=dif/2;
            a[rpointer]+=dif/2;
            dif%=2;
            if(totalr>totall&&dif>0)
                a[rpointer]++;
            else if(totall>totalr&&dif>0)
                a[lpointer]++;
            long long int x=max(totall,totalr)-1;
            if(x%2)
                swap(a[rpointer],a[lpointer]);


    for(i=0;i<n;i++)
        cout<<a[i]<<" ";
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); 
  int a,b;
  cin >> a >> b;
  if(a<=9 && b<=9){cout << a*b << endl;}
  else{cout << -1 << endl;}
}

Measured memory_bytes: 256
using System;

namespace AOJ.ITP
{
    public class Shuffle
    {
        public static void Main()
        {
            while (true)
            {
                string test = Console.ReadLine();
                if (test == "-") { break; }

                int cnt = int.Parse(Console.ReadLine());
                for (int i = 0; i < cnt; i++)
                {
                    int pos = int.Parse(Console.ReadLine());
                    test = test.Substring(pos) + test.Substring(0, pos);
                }
                Console.WriteLine(test);
            }
        }
    }
}

Measured memory_bytes: 5320
#include<iostream>
#include<algorithm>

using namespace std;

int main(void)
{
  string s; cin>>s;
  int a_num=s.find('A');
  int z_num=s.rfind('Z');
  int count=z_num-a_num+1;
  
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;
 
#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7
 
typedef long long ll;
typedef long long int lli;
 
int main() {
	int N, res, max;
	cin >> N;
    res = 0;
    for (int i = 0; i < N; i++) {
        int Hi;
        cin >> Hi;
        if (i == 0) {
            max = Hi;
        }else {
            if (max <= Hi) {
                max = Hi;
                res++;
            }
        }
    }
	cout << res+1 << endl;
	return 0;
}

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

using namespace std;

int N;
string in;

int main() {
	cin >> in;
	N = in.size();
	char bef = in[0];
	int ans = N;
	for (int i = 1; i < N; i++) {
		if (bef != in[i]) {
			ans = min(max(i , N - i), ans);
			bef = in[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;
}

Measured memory_bytes: 3596