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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define fout(x) cout << fixed << setprecision(10) << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  VI p(m); vector<string> s(m);
  rep(i, m) cin >> p[i] >> s[i];
  map<int, int> ac, wa;
  int aac, awa;
  aac = awa = 0;
  rep(i, m) {
    if(s[i] == "AC") {
      ac[p[i]]++;
      if(ac[p[i]] == 1) {
        aac++;
        awa += wa[p[i]];
      }
    }
    else wa[p[i]]++;
  }
  cout << aac << " " << awa << endl;
  return 0;
}


Measured memory_bytes: 15488
#!/usr/bin/env python3
def primes(n):
    m = 1303
    is_prime = [True] * (m + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(m**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, m + 1, i):
            is_prime[j] = False
    return [i for i in range(m + 1)
            if is_prime[i] and str(i).endswith("3")][:n]


print(*primes(int(input())))


Measured memory_bytes: 9460
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }

int main() {

	long N, M; cin >> N >> M;

	multiset<long> A;
	vector<long> m(N); //割引券を使う枚数

	for (int i = 0; i < N; i++) { long a; cin >> a; A.insert(a); } //昇順

	while (M--) {
		long amax = *A.rbegin();
		A.erase(--A.end(), A.end());
		amax /= 2;
		A.insert(amax);
	}
    long res = 0;
    for (auto e : A) res += e;
    
	cout << res << endl;

}

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

int a[111], n;

int main() {
    cin >>n;
    int sum = 0;
    for(int i=0;i<n;i++) {
        cin >>a[i];
        a[i] *= n;
        sum += a[i];
    }
    sum /= n;
    int ans = -1;
    int different = 1e9;
    for (int i = 0; i < n; i++) {
        if (different > abs(a[i] - sum)) {
            different = abs(a[i] - sum);
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

const int INF = 1 << 30;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i] >> B[i];
    }
    vector<vector<int>> dp(N+1, vector<int>(H+1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j <= H; j++)
        {
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][min(j+A[i], H)], dp[i+1][j]+B[i]);
        }
        
    }
    cout << dp[N][H] << endl;
}

Measured memory_bytes: 39424
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> pll;
const ll inf = 1LL << 60;

bool compare(P a, P b){
    return a.second < b.second;
}

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

    int N,M,Q;cin>>N>>M>>Q;
    vector<P> train(M);
    REP(i,M){
        int l,r; cin>>l>>r;
        train[i] = P(l,r);
    } 
    sort(ALL(train), compare);
    vector<vector<int> > ruiseki(N+1,vector<int>(N+1,0));
    for(int left =1 ; left <= N; left++){
        int now = 0;
        int itr = 0;
        for(int right = left; right <= N; right++){
                while(train[itr].second <= right){
                    if(train[itr].first >= left){
                        now++;
                    }
                    itr++;
                    if(itr >= M) break;
                }
            ruiseki[left][right] = now;
        }
        
    }
    vector<int> ans(Q);
    REP(i,Q){
        int l,r; cin>>l>>r;
        ans[i] = ruiseki[l][r];
    }

    REP(i,Q){
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 3840
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  string s;
  cin >> s;

  int ans = s.size();
  for (int i = 1; i < s.size(); i++) {
    if (s[i-1] == s[i]) continue;

    ans = min(ans, max(i, (int)s.size() - i));
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = 1e18;

int main(int argc, char* argv[])
{
  int N;
  std::cin >> N;

  if ((N / 100) == N % 10) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;
    S='#'+S+'#';
    int ok=1;
    auto two_rocks = [&](int s,int e){
        for(int i=s;i<=e;i++){
            if(S[i]=='#'&&S[i+1]=='#')return false;
        }
        return true;
    };
    if(!two_rocks(A,C)||!two_rocks(B,D))ok=0;
    if(C>D){
        int flag=0;
        for(int i=B;i<=D;i++){
            if(S[i-1]=='.'&&S[i]=='.'&&S[i+1]=='.')flag=1;
        }
        if(!flag)ok=0;
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 772
#include <iostream>
#include <cstdio>
#include <cassert>

using namespace std;


class Solution{

public:
    long long minbase(long long n, long long s){

        long long b;
        for(b = 2ll; b * b <= n; b ++)
            if(sum(n, b) == s) return b;
//        assert(b * b > n);

        if(s == n) return n + 1ll;
//        if(s == 1ll) return n;

        long long res = LONG_LONG_MAX;
        for(long long k1 = 1; k1 < b; k1 ++){
            long long k2 = s - k1;
            if(k2 >= 0 && (n - k2 > 0) && (n - k2) % k1 == 0){
                long long tb = (n + k1 - s) / k1;
                if(k1 < tb && k2 < tb){
//                    assert(sum(n, tb) == s);
                    res = min(res, tb);
                }
            }
        }
        return res == LONG_LONG_MAX ? -1 : res;
    }

private:
    long long sum(long long n, long long b){

        long long res = 0ll;
        while(n){
            res += n % b;
            n /= b;
        }
        return res;
    }
};


int main() {

//    cout << Solution().minbase(87654ll, 30ll) << endl;
//    // 10
//
//    cout << Solution().minbase(87654ll, 138ll) << endl;
//    // 100
//
//    cout << Solution().minbase(87654ll, 45678ll) << endl;
//    // -1
//
//    cout << Solution().minbase(31415926535ll, 1ll) << endl;
//    // 31415926535
//
//    cout << Solution().minbase(1ll, 31415926535ll) << endl;
//    // -1
//
//    cout << Solution().minbase(31415926535ll, 31415926535ll) << endl;
//    // -1
//
//    cout << Solution().minbase(100000000000ll, 1ll) << endl;
//    // 10
//
//    cout << Solution().minbase(1ll, 1ll) << endl;
//    // 2

    long long n, s;
    scanf("%lld%lld", &n, &s);
    printf("%lld\n", Solution().minbase(n, s));

    return 0;
}


Measured memory_bytes: 3216
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;


int main()
{
	int n;
	ll tmp;
	vector<ll> h, h2;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> tmp; 
		h.push_back(tmp);
	}

	int i=0,cnt=0;
	h2.push_back(0);
	while(i<n-1){
		while(h[i]>=h[i+1] && i<n-1){
			cnt++;
			i++;
		}
		h2.push_back(cnt);	
		i++;
		cnt =0;
	}

	ll max = *max_element(h2.begin(), h2.end());
	cout << max;

}

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

using namespace std;

const int MOD = 1e9 + 7;

long long fact[2000005], inv[2000005];
char s[1000005];

long long mypow(long long x, long long y) {
	long long res = 1;
	while (y) {
		if (y & 1) res = res * x % MOD;
		y >>= 1;
		x = x * x % MOD;
	}
	return res;
}

long long ncr(int x, int y) {
	if (y < 0 || y > x) return 0;
	return fact[x] * inv[y] % MOD * inv[x - y] % MOD;
}

int main() {
	int k;
	scanf("%d", &k);
	scanf("%s", s);
	int l = strlen(s);
	
	fact[0] = 1;
	for (int i = 1; i <= k + l; i++) {
		fact[i] = fact[i - 1] * i % MOD;
	}
	inv[k + l] = mypow(fact[k + l], MOD - 2);
	for (int i = k + l - 1; i >= 0; i--) {
		inv[i] = inv[i + 1] * (i + 1) % MOD;
	}
	
	long long res = 0;
	
	for (int i = l; i <= k + l; i++) {
		res = (res + ncr(i - 1, l - 1) * mypow(25, i - l) % MOD * mypow(26, k + l - i) % MOD) % MOD;
	}
	
	printf("%lld\n", res);
}


Measured memory_bytes: 35944
n=int(input())
a=[[int(_),0] for _ in input().split()]
for i in range(n): a[i][1]=i
a.sort(reverse=True)
dp=[[0 for _ in range(n)] for __ in range(n)]
for l in range(n):
    for r in range(n):
        if l+r < n:
            if l<n-1:dp[l+1][r]=max(dp[l+1][r], dp[l][r]+a[l+r][0]*abs(a[l+r][1]-l))
            if r<n-1:dp[l][r+1]=max(dp[l][r+1], dp[l][r]+a[l+r][0]*abs(a[l+r][1]-(n-r-1)))
print(max([dp[i][n-i] for i in range(1,n)]))

Measured memory_bytes: 107376
/*ITP1_4_A:A / B Problem*/
#include <iostream>
//#include <stdio.h>
using namespace std;

int main() {

    int a,b;
    cin >> a >> b;
//    double tmp;
//    tmp = (double)a/(double)b;
//    printf("%d %d %lf\n",a/b,a%b,tmp);
    cout << a/b << " " << a%b << " " << fixed << (double)a/b << endl;
    return 0;
}



Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> py[100001];
    vector<int> p(100000);
    vector<int> y(100000);
    for(int i=0;i<m;i++){
        cin>>p[i]>>y[i];
        py[p[i]].push_back(y[i]);
    }
    for(int i=0;i<n;i++){
        sort(py[i+1].begin(),py[i+1].end());
    }
    for(int i=0;i<m;i++){
        printf("%06d%06d\n",p[i],int(lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i])-py[p[i]].begin())+1);
    }
    return 0;
}


Measured memory_bytes: 7808
N = int(input())

a = list(map(int,input().split()))
b = sorted(a,reverse=True)
Alice =[]
Bob =[]
for i in range(N):
    if (i+1)%2 !=0:
        Alice.append(b[i])
    else:
        Bob.append(b[i])

print(sum(Alice)-sum(Bob))

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;

ll euclid(ll a, ll b)
{
    int nr = 0;
    while (b != 0)
    {
        int c = b;
        b = a % b;
        a = c;
        nr++;
    }
    return nr;
}


int main()
{
    int n;
    cin >> n;
    ll monsters = 0;
    vector<ll> v(n+1);
    vector<ll> b(n);
    for (int i = 0; i < n+1; i++)
    {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++)
    {
        ll minim = min(v[i], b[i]);
        monsters += minim;
        b[i] -= minim;
        v[i] -= minim;
        minim = min(v[i+1], b[i]);
        monsters += minim;
        b[i] -= minim;
        v[i+1] -= minim;

    }
    cout << monsters;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int a,b,c;
int main(){
	cin>>a>>b>>c;
	cout<<b+c-min(a,b+c)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
#define fr second.first
#define to second.second
#define co first
const int INF=INT_MAX;
typedef pair<int,int> P;
typedef pair<int,P> Edge;
long long edmonds(vector<Edge> edges,int v,int st) {
 
  vector<P> mins(v,P(INF,-1));
  for(int i=0;i<(int)edges.size();i++) {
    Edge edge=edges[i];
    mins[edge.to]=min(mins[edge.to],P(edge.co,edge.fr));
  }
  mins[st]=P(-1,-1);
  
  vector<int> gr(v,0);
  vector<bool> tfc(v,false),f(v,false);
  int cnt=0; 

  for(int i=0;i<v;i++){
    if(f[i]) continue;
    vector<int> ch;
    int cu=i;
    for(;cu!=-1&&!f[cu];){ 
      f[cu]=true;
      ch.push_back(cu);
      cu=mins[cu].second;
    }
    if(cu!=-1){
      bool tfc2=false;
      for(int j=0;j<(int)ch.size();j++) {
	gr[ch[j]]=cnt;
	if(ch[j]==cu){
	  tfc[cnt]=true;
	  tfc2=true;
	}
	if(!tfc2) cnt++;
      }
      if(tfc2) cnt++;
    }
    else for(int j=0;j<(int)ch.size();j++,cnt++) gr[ch[j]]=cnt;
  }

  if(cnt==v){
    long long ans=1;
    for(int i=0;i<v;i++) ans+=mins[i].co;
    return ans;
  }

  long long res=0;
  for(int i=0;i<v;i++) if(i!=st&&tfc[gr[i]]) res+=mins[i].co;
    
  vector<Edge> nedges;
  for(int i=0;i<(int)edges.size();i++) {
    Edge edge=edges[i];
    int fto=edge.to,gfr=gr[edge.fr],gto=gr[edge.to];
    if(gfr==gto) continue;
    else if(tfc[gto]) nedges.push_back(make_pair(edge.co-mins[fto].co,P(gfr,gto)));
    else nedges.push_back(make_pair(edge.co,P(gfr,gto)));
  }

  return res+edmonds(nedges,cnt,gr[st]);

}

int main(){
  int v,e,r;
  cin>>v>>e>>r;
  vector<Edge> es;
  for(int i=0,s,t,w;i<e&&cin>>s>>t>>w;i++) es.push_back(make_pair(w,P(s,t)));
  cout<<edmonds(es,v,r)<<endl;
  return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

//snuke
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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 { mint res(*this); return res+=a; }
  mint operator-(const mint a) const { mint res(*this); return res-=a; }
  mint operator*(const mint a) const { mint res(*this); return res*=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 { mint res(*this); return res/=a; }
}; 

vector<ll> inv,fact,invfact;
void mod_build(int n=101010){  
  fact.resize(n+1); inv.resize(n+1); invfact.resize(n+1);
  fact[0]=inv[0]=invfact[0]=1; inv[1]=1;
  rep(i,n){
    fact[i+1]=fact[i]*(i+1)%mod;
    if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
    invfact[i+1]=invfact[i]*inv[i+1]%mod;
  }
}
ll perm(int n,int k){ if(n<0||k<0||k>n){ return 0; } else { return fact[n]*invfact[n-k]%mod; } }
ll comb(int n,int k){ if(n<0||k<0||k>n){ return 0; } else { return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod; }}
ll powmod(ll n,ll k){
  k%=mod-1; if(k<0)k+=mod-1;
  ll ret=1; while(k){ if(k&1)ret=ret*n%mod; n=n*n%mod; k>>=1; }
  return ret;
}

int main(){  
  mod_build();
  int n,k;
  cin >> n >> k;
  vector<ll> a(n,0);  
  rep(i,n){ cin>>a[i]; }

  sort(a.rbegin(),a.rend());
  mint ans=0;
  for(ll i=0; i<n-k+1; i++){
    ans += (a[i]*comb(n-i-1,k-1));
  }

  sort(a.begin(),a.end());
  mint ansb=0;
  for(ll i=0; i<n-k+1; i++){
    ansb += (a[i]*comb(n-i-1,k-1));
  }

  ans = ans-ansb;
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    string a;
    cin>>a;
    char k[4];
    for(int i = 0;i<a.length();i++){
      k[i] = a[i];
    }
    sort(k,k+4);
    if(k[0] == k[1] && k[2] == k[3] && k[0]!=k[3]) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

from collections import deque

def main():
	m,k=MI()
	A=[]
	if k==0:
		for i in range(2**m):
			A.append(i)
			A.append(i)
		print(*A)
		exit()

	if 2**(m)<=k:
		print(-1)
		exit()

	if m==k==1:
		print(-1)
		exit()

	A.append(0)
	A.append(k)
	A.append(0)

	for i in range(1,2**m):
		if i!=k:
			A.append(i)
	A.append(k)

	for i in reversed(range(1,2**m)):
		if i!=k:
			A.append(i)

	print(*A)


















if __name__ == "__main__":
	main()


Measured memory_bytes: 100692
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}

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

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

    int n,m;
    cin >> n >> m;

    vector<vector<int> > g(n+1);

    rep(i,m){
        int a,b;
        cin >> a >> b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    vector<int> dist(n+1,INF);
    queue<int> que;
    dist[1] = 0;
    que.emplace(1);

    while(!que.empty()){
        int now = que.front();
        que.pop();
        rep(i,g[now].size()){
            int next = g[now][i];
            if(dist[now] + 1 <= 2 && dist[next] > dist[now] + 1){
                dist[next] = dist[now] + 1;
                que.emplace(next);
            }
        }
    }
    
    if(dist[n] == INF) cout << "IMPOSSIBLE\n";
    else cout << "POSSIBLE\n";

    return 0;
}


Measured memory_bytes: 15208
Base = [[1, 2, 3, 4, 5, 6],
        [1, 3, 5, 2, 4, 6],
        [1, 5, 4, 3, 2, 6],
        [1, 4, 2, 5, 3, 6],
        [5, 1, 3, 4, 6, 2],
        [5, 3, 6, 1, 4, 2],
        [5, 6, 4, 3, 1, 2],
        [5, 4, 1, 6, 3, 2],
        [6, 5, 3, 4, 2, 1],
        [6, 3, 2, 5, 4, 1],
        [6, 2, 4, 3, 5, 1],
        [6, 4, 5, 2, 3, 1],
        [2, 6, 3, 4, 1, 5],
        [2, 3, 1, 6, 4, 5],
        [2, 1, 4, 3, 6, 5],
        [2, 4, 6, 1, 3, 5],
        [4, 1, 5, 2, 6, 3],
        [4, 5, 6, 1, 2, 3],
        [4, 6, 2, 5, 1, 3],
        [4, 2, 1, 6, 5, 3],
        [3, 5, 1, 6, 2, 4],
        [3, 1, 2, 5, 6, 4],
        [3, 2, 6, 1, 5, 4],
        [3, 6, 5, 2, 1, 4]]

class Dice
  def initialize(arr)
    @all = []
    Base.each { |b|
      temp = Array.new(6)
      for j in 1..6
        temp[j - 1] = arr[b[j - 1] - 1]
      end
      @all.push(temp)
    }
  end

  def getall()
    return @all
  end
end

first = Dice.new(gets.split.map(&:to_i)).getall()

if first.include?(gets.split.map(&:to_i))
  puts "Yes"
else
  puts "No"
end



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

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define b_e(a) a.begin(),a.end() //sort(b_e(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll)(n) ; i++ )
#define DREP(i,m,n) for(ll i=(ll)(m) ; i > (ll)(n) ; i-- )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define p_b push_back
#define SZ(x) ((ll)(x).size()) //size()がunsignedなのでエラー避けに
#define endk '\n'


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //


// --------- library end - //



int main(){

  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  vector<ll> ans(4);

  ans[0] = a * c;
  ans[1] = a * d;
  ans[2] = b * c;
  ans[3] = b * d;


  cout << *max_element(b_e(ans)) << endk;

}



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007


const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
vector<vector<ll> > G;
vector<bool> seen(100010);
vector<vector<ll>> gr;
vector<ll> tmp;
vector<vector<ll>> F2;
//ll fcnt=1;
ll dis;
ll cnt = 0;
vector<ll> root(100010,-1);

void dfs(ll v){
    seen[v] = 1;
    tmp.pb(v);
    root[v] = cnt;
    rep(i,F2[v].size()){
        if(seen[F2[v][i]] == 0){
            dfs(F2[v][i]);
            
        }
    }

}

int main() {

    ll N,M,K;
    cin >>N>>M>>K;
    F2.resize(N);
    vector<Pi> F3(M);
    vector<Pi> B3(K);

    rep(i,M){
        ll a,b;
        cin >>a>>b;
        a--;
        b--;
        F2[a].pb(b);
        F2[b].pb(a);
        F3[i]= mp(a,b);
    }

    rep(i,K){
        ll a,b;
        cin >>a>>b;
        a--;
        b--;
        B3[i] = mp(a,b);
    }

    

    rep(i,N){
        if(seen[i] == 0){
            gr.emplace_back();
            dfs(i);
            gr[cnt] = tmp;
            cnt++;
            tmp.clear();
        }
    }

    vector<ll> ans(N);
    rep(i,cnt){
        rep(j,gr[i].size()){
            ans[gr[i][j]] = gr[i].size()-1;
        }
    }

    
    rep(i,M){
        ans[F3[i].first]--;
        ans[F3[i].second]--;
    }
    

    rep(i,K){
        if(root[B3[i].first] == root[B3[i].second]){
            ans[B3[i].first]--;
            ans[B3[i].second]--;
        }
        
    }

    rep(i,N){
        cout <<ans[i]<<" ";
    }
    cout<<endl;


    return 0;
    

}

Measured memory_bytes: 18084
# include <iostream>
# include <math.h>

using namespace std;

int main()
{
    string S;
    string T;

    cin >> S;
    cin >> T;

    int changes = 0;

    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] != T[i])
            changes++;
    }

    cout << changes;

    return 0;
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
#define N 300050
#define ll long long
#define x first
#define y second
#define all(v) v.begin(),v.end()
using namespace std;

int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
            cout.tie(NULL);
            ll h;
            cin>>h;
            ll cu = h,  nu = 1;
            ll ans = 0;
            while(cu>0){
                if(cu==1){
                    ans+=nu;
                    break;
                }
                ans+=nu;
                nu+=nu;
                cu/=2ll;
            }
            cout<<ans;
            return 0;
}


Measured memory_bytes: 256
def func(x,y):
    return  x if x < y else y

class SegmentTree:
    def __init__(self, n): #a1, a2, ..., an
        n_ = 1
        while n_ < n:
            n_ *= 2

        self.n = n_
        self.arr = [2**31-1] * (2*self.n-1)

    def update(self, k, a): #0_indexed
        k += self.n - 1
        self.arr[k] = a

        while k > 0:
            k = (k-1) // 2
            self.arr[k] = func(self.arr[2*k+1], self.arr[2*k+2])

    def query(self, l, r):#[l,r)の値を返す
        L, R = l+self.n, r+self.n
        ide_ele = 2**31-1
         #ex) 最小値のセグ木 → +inf
         #　和のセグ木 → 0
         #　積のセグ木 → 1
         #  gcdのセグ木 → 0
        res = ide_ele
        while L < R:
            if R & 1:
                R -= 1
                res = func(res, self.arr[R-1])

            if L & 1:
                res = func(res, self.arr[L-1])
                L += 1

            L >>= 1
            R >>= 1

        return res
#0-indexedな気がする
n,q=map(int,input().split())
sg=SegmentTree(n)
for _ in range(q):
    c,x,y=map(int,input().split())
    if c==0:
        sg.update(x,y)
    else:
        print(sg.query(x,y+1))



Measured memory_bytes: 8692
# coding: utf-8
# Your code here!

import itertools
n=int(input())
l = [i for i in range(1,n+1)]
a=list(map(int,input().split()))
b=list(map(int,input().split()))
cnt=1
ans_a=0
ans_b=0
for v in itertools.permutations(l):
    if list(v)==a:
        ans_a=cnt
    if list(v)==b:
        ans_b=cnt        
    if ans_a!=0 and ans_b!=0:
        break
    cnt+=1
print(abs(ans_a-ans_b))

Measured memory_bytes: 9124
from operator import itemgetter

n = int(input())
w = []
for i in range(n):
    s,p = map(str,input().split())
    p = int(p)
    w.append((s,p,i))
w = list(sorted(w,key=itemgetter(1),reverse=True))
w = list(sorted(w,key=itemgetter(0)))

for i in range(n):
    print(w[i][2]+1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
#define ll long long int
using namespace std;

int main() {
	int N, M, C; cin >> N >> M >> C;
	vector<int> B(M); 
	for (int i = 0; i < M; i++)cin >> B[i];
	int A[N][M];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int res = C;
		for (int j = 0; j < M; j++) {
			res += A[i][j] * B[j];
		}

		if (res > 0) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <ctime>

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

using namespace std;

// defines
#define rep(i, N) for (i=0;i<(N);i++)
#define sqr(x) (x) * (x)
#define all(v) (v.begin(), v.end())
#define pb push_back
#define random (rand() << 16 ^ rand())

// Typedefs
typedef pair<int, int> ii;

// constants
const int64_t inf = 1e18+7;
const int64_t mod = 1e9+7;


int main() {
	int N, i;
	int64_t ans = 0LL;

	cin >> N;
	rep(i, N) {
		int64_t t;
		cin >> t;

		while (t%2LL == 0LL) {
			ans++;
			t /= 2LL;
		}
	}

	cout << ans << endl;

	return 0;
}


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

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

  ll res = 0;

  for (ll r = 1; r * r <= n; r++) {
    if ((n - r) % r == 0 && (n - r)/r > r) res += (n-r)/r;
  }
  cout << res << endl;
  return 0;
} 

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 1e9 + 1
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

#define MAX_N 100
#define MAX_M 100

int main(){
    int n;
    cin >> n;
    set<string> st;
    REP(i, n) {
        string s;
        cin >> s;
        st.insert(s);
    }

    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 19260
#include <bits/stdc++.h>
#include <vector>
using namespace std;
using pll = pair<long long, long long>; 


int main(){
    int n;
    int ans=0;
    cin>>n;
    vector<int> t(n);
    for (int i=0; i<n; i++) {
        cin>>t[i];
        ans+=t[i];
    }
    int m;
    cin>>m;
    vector<int> p(m);
    vector<int> x(m);
    for (int i=0; i<m; i++) cin>>p[i]>>x[i];
    for (int i=0; i<m; i++){
        cout<<ans-t[p[i]-1]+x[i]<<endl;
    }
}


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

int main (void){
  string s;
  cin >> s;
  
  string ans = "Yes";
  for(int i = 0; i < s.size();i++){
    if(i % 2 == 1){
      if(s[i] == 'R'){
        ans = "No";
      }
    } else{
      if(s[i] == 'L'){
        ans = "No";
      }
    }
  }
  cout << ans;
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    vector<set<int>> is(26);
    rep(i, n) {
        is[s[i]-'a'].insert(i);
    }
    rep(qi, q) {
        int ty;
        cin >> ty;
        if ( ty == 1 ) {
            int i; char c;
            cin >> i >> c;
            --i;
            is[s[i]-'a'].erase(i);
            s[i] = c;
            is[s[i]-'a'].insert(i);
        }
        else {
            int l, r;
            cin >> l >> r;
            --l;
            int ans = 0;
            rep(i, 26) {
                auto it = is[i].lower_bound(l);
                if ( it != is[i].end() && *it < r ) ++ans;
            }
            printf("%d\n", ans);
        }
    }
    return 0;
}


Measured memory_bytes: 24196
#include <stdio.h>
int main(void){
  int n,h[100000];
  int i, x = 0, sum = 0, max = 0;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&h[i]);
    if(x >= h[i]){
      sum++;
    }
    else{
      if(sum >= max){
        max = sum;
      }
      sum = 0;
    }
    x = h[i];
  }
  if(sum >= max){
    max = sum;
  }
  printf("%d",max);
  return 0;
}


Measured memory_bytes: 512
from fractions import gcd

N = int(input())
A = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7


def modinv(a, mod=10 ** 9 + 7):
    return pow(a, mod - 2, mod)

lcm = A[0]
for i in range(1, N):
    lcm = (lcm * A[i] // (gcd(lcm, A[i])))
ans = 0
lcm %= MOD

for a in A:
    ans = (ans + lcm * modinv(a)) % MOD

print(ans)

Measured memory_bytes: 6116
module Memoizable
	def memoize(name)
		original = "__original_#{name}__"
		([Class, Module].include?(self.class) ? self : self.class).class_eval {
			alias_method(original, name)
			private(original)
			cache = {}
			define_method(name){|*args|
				cache[args] ||= send(original, *args)
			}
		}
	end 

	#def memoize(name)
	#	original = "__original_#{name}__"
	#	klass = ([Class, Module].include?(self.class) ? self : self.class)
	#	klass.class_eval <<-"EOS"
	#		alias_method('#{original}', '#{name}')
	#		private('#{original}')
	#		@@cache_for_#{name} = {}
	#		def #{name}(*args)
	#			@@cache_for_#{name}[args] ||= send('#{original}', *args)
	#		end
	#	EOS
	#end 
end

include Memoizable

$n = gets.to_i
$a = gets.split.map &:to_i

def f(left, i)
	if i == $n-1
		return left == $a[i] ? 1 : 0
	end
	sum = 0
	sum += f(left - $a[i], i+1) if left >= $a[i]
	sum += f(left + $a[i], i+1) if left + $a[i] <= 20
	sum
end

memoize :f

p f($a[0], 1)

Measured memory_bytes: 6252
X, Y = map(int, input().split())
 
if (1 <= X <= 100) and (1 <= Y <= 100):
  kame = ( Y - (2 * X)) / 2
  turu = (Y - (4 * X)) / -2
  
  if kame.is_integer() and turu.is_integer() and kame >= 0 and turu >= 0:
  	print("Yes")
  else:
    print("No")

Measured memory_bytes: 9144
module Main where

import Data.List

main :: IO()
main = do
  getLine
  sticks <- map read . words <$> getLine
  print $ solve sticks

solve :: [Int] -> Int
solve = calcArea . concatMap (halfnize . flatten2r4) . filter (\g -> length g >= 2) . group . sortOn (\a -> -a)

flatten2r4 :: [Int] -> [Int]
flatten2r4 xss@(x:xs)
  | length xss == 2 = xss
  | length xss == 4 = xss
  | length xss == 3 = xs
  | length xss > 4  = flatten2r4 xs
  | otherwise       = error "おかしい"

calcArea :: [Int] -> Int
calcArea (x:y:_) = x * y
calcArea _ = 0

halfnize :: [Int] -> [Int]
halfnize ss = take (length ss `div` 2) ss


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

int main() {
    int x,y,z;
    cin>>x>>y>>z;
    x-=z;
    ll ans=x/(y+z);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
char s[15];
bool ok;
int main()
{ cin>>s;
  if(s[0]!='A')
  { cout<<"WA";
    return 0;
  }
  for(int i=2;i<strlen(s)-1;i++)
  { if(s[i]=='C' && !ok)
       ok=1;
    else if(s[i]=='C' && ok)
    { cout<<"WA";
      return 0;
    }
    if(s[i]!='C' && 'A'<=s[i] && s[i]<='Z')
    { cout<<"WA";
      return 0;
    }
  }
  if(!ok)
  { cout<<"WA";
    return 0;
  }
  if('A'<=s[1] && s[1]<='Z')
  { cout<<"WA";
    return 0;
  }
  if('A'<=s[strlen(s)-1] && s[strlen(s)-1]<='Z')
  { cout<<"WA";
    return 0;
  }
  cout<<"AC";
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
 int a,b,menseki,syuui;

 scanf("%d %d",&a, &b);

 
 menseki = a*b ;
 syuui = 2*a + 2*b ;

 printf("%d %d\n", menseki, syuui);

 return 0;
}

Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+4;
int dp[maxn], h[maxn];

int main() {
	int n;
	cin>>n;
	for(int i=0; i<n; i++) {
	    cin>>h[i];
	    dp[i] = 1e9;
	}
	
	dp[0] = 0;
	for(int i=0; i<n-1; i++) {
	    dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
	    
	    if(i+2<n)
	        dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i])); 
	}
	
	cout<<dp[n-1]<<endl;
// 	for(int i=0; i<n; i++) {
// 	    cout<<dp[i]<<" ";
// 	}
	return 0;
}

Measured memory_bytes: 1024
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

class FactInv:
    def __init__(self, N, MOD=MOD):
        fact, inv = [1]*(N+1), [None]*(N+1)
        for i in range(1, N+1): fact[i] = fact[i - 1] * i % MOD
        inv[N] = pow(fact[N], MOD - 2, MOD)
        for i in range(N)[::-1]: inv[i] = inv[i + 1] * (i + 1) % MOD
        self.N, self.MOD, self.fact, self.inv = N, MOD, fact, inv

    def perm(self, a, b):
        if a > self.N or b > self.N: raise ValueError("\nPermutaion arguments are bigger than N\n N = {}, a = {}, b = {}".format(self.N, a, b))
        return self.fact[a] * self.inv[a-b] % self.MOD

    def comb(self, a, b):
        if a > self.N or b > self.N: raise ValueError("\nCombination arguments are bigger than N\n N = {}, a = {}, b = {}".format(self.N, a, b))
        return self.fact[a] * self.inv[b] * self.inv[a-b] % self.MOD

class Eratosthenes:
    # https://cp-algorithms.com/algebra/prime-sieve-linear.html
    def __init__(self, n):
        primes, lp = [], [0] * (n + 1)
        for i in range(2, n + 1):
            if lp[i] == 0:
                primes.append(i)
                lp[i] = i

            for pj in primes:
                if pj > lp[i] or i * pj > n: break
                lp[i * pj] = pj
        self.primes, self.lp = primes, lp

    def is_prime(self, x): return self.lp[x] == x

    def factors(self, x):
        ret = []
        while x > 1:
            ret.append(self.lp[x])
            x //= self.lp[x]
        return ret

def main():
    N = I()
    A = LI()

    era = Eratosthenes(max(A))
    factors = Counter()

    for ai in A:
        cai = Counter(era.factors(ai))
        for k in cai.keys():
            factors[k] = max(factors[k], cai[k])

    lcm = 1
    for k, v in factors.items():
        lcm = lcm * pow(k, v, MOD) % MOD

    ans = 0
    for ai in A:
        ans = (ans + lcm * pow(ai, MOD - 2, MOD)) % MOD

    print(ans)





if __name__ == '__main__':
    main()

Measured memory_bytes: 90432
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    a = 1000;
    cin >> b;
    int oturi=0;

    for(int i=0;i<10;i++){
        if(a>=b){
            oturi = a-b;
            break;
        }else{
            a += 1000;
        }
    }
    cout << oturi;
}


Measured memory_bytes: 3644
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    // 入力を取得
    int a = sc.nextInt();
    int b = sc.nextInt();
    int k = sc.nextInt();

    ArrayList<Integer> divisor  = new ArrayList<Integer>();
    for(int i= a;i>0;i--){
      if(a%i==0 && b%i==0){
        divisor.add(i);
      }
    }

    // 出力
    System.out.println(divisor.get(k-1));
  }
}


Measured memory_bytes: 23124
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    string s; cin>>s;

    bool valid = false;
    for(int i=0; i<3; i++){
        if(s[i] == '7') valid = true;
    }

    cout << (valid ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
    int V, E;
    cin >> V >> E;
    vector<vector<long long>> dist(V, vector<long long>(V, INF));
    for (int i = 0; i < E; i++)
    {
        long long s, t, d;
        cin >> s >> t >> d;
        dist[s][t] = d;
    }

    for (int i = 0; i < V; i++)
    {
        dist[i][i] = 0;
    }

    bool mc = false;
    for (int k = 0; k < V; k++)
    {
        for (int i = 0; i < V; i++)
        {
            for (int j = 0; j < V; j++)
            {
                if(dist[i][k] != INF && dist[k][j] != INF)
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    for (int i = 0; i < V; i++)
    {
        if(dist[i][i] < 0) mc = true;
    }

    if(mc) cout << "NEGATIVE CYCLE" << endl;
    else{
        for (int i = 0; i < V; i++)
        {
            for (int j = 0; j < V; j++)
            {
                if(dist[i][j] == INF) cout << "INF";
                else cout << dist[i][j];
                if(j == V - 1) cout << endl;
                else cout << " ";
            }
        }
    }
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \
  cout << #v << "=(" << v[0];                                                  \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; }                     \
  cout << ")" << endl;
#define mdebug(m)                                                              \
  cout << #m << "=" << endl;                                                   \
  REP(i_debug, m.size()) {                                                     \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \
    cout << endl;                                                              \
  }
#define Lower_bound(v, x)                                                      \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
// #define f first
// #define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}

ll mod = 1000000007;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  while (a > 0) {
    c -= b;
    if (c <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    a -= d;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d) cout<<"Left";
  if(a+b<c+d) cout<<"Right";
  if(a+b==c+d) cout<<"Balanced";
  cout<<"\n";
}


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

int main() {
  
  int n;
  cin >> n;
  
  int hantei = 0;
  int sum = 0;
  
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if(a % 2 == 0) {
      sum += 1;
      if(a % 3 == 0 || a % 5 == 0) {
        hantei += 1;
      }
    }
  }
  
  if (hantei == sum) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int M;
    cin >> M;
    ll S = 0;
    ll C = 0;
    rep(i, M) {
        ll d, c;
        cin >> d >> c;
        S += d * c;
        C += c;
    }

    ll ans = C - 1;
    ans += (S - 1) / 9;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#define ll long long
#define endl "\n"
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
   int n,sum=0,maxi=200001;
   cin>>n;
   int arr[n];

   for(int i=0;i<n;i++)
   {
       cin>>arr[i];
       if(arr[i]<maxi)
       {
           sum++;
           maxi=arr[i];
       }
   }
   cout<<sum<<endl;
    return 0;
}


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

string s, t;
int S, T;

bool match(int k)
{
  for (int i = 0; i < T; i++)
  {
    if (t[i] != s[i + k] && s[i + k] != '?')
    {
      return false;
    }
  }
  return true;
}

string construct(int k)
{
  string ans = s;

  for (int i = 0; i < T; i++)
  {
    ans[k + i] = t[i];
  }

  for (int i = 0; i < S; i++)
  {
    if (ans[i] == '?')
    {
      ans[i] = 'a';
    }
  }
  return ans;
}

int main()
{
  string ans;
  bool flg;
  cin >> s >> t;
  S = s.length();
  T = t.length();

  for (int i = S - 1; i >= 0; i--)
  {
    flg = match(i);
    if (flg)
    {
      ans = construct(i);
      break;
    }
  }
  if (flg)
  {
    cout << ans << endl;
  }
  else
  {
    cout << "UNRESTORABLE" << endl;
  }
}


Measured memory_bytes: 3564