akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
ab = [[False]*N for _ in range(N)]

for m in range(M):
    a, b = map(int, input().split())
    ab[a-1][b-1] = True
    ab[b-1][a-1] = True


def solve(n, visit):
    if all(visit):
        return 1
    c = 0
    for i in range(N):
        b = ab[n][i]
        if b and not visit[i]:
            visit[i] = True
            c += solve(i, visit)
            visit[i] = False
    return c


print(solve(0, [True]+[False]*(N-1)))


Measured memory_bytes: 42844
#include <bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;

const int N = 3e3 + 5, inf = 1e18, mod = 1e9 + 7;

int n, m, maxLen, dp[N][N];
string s, t;

int go(int id1, int id2){
    if(id1 >= n || id2 >= m)
        return 0;
    int& ans = dp[id1][id2];
    if(~ans)
        return ans;
    int c1 = 0;
    if(s[id1] == t[id2])
        c1 = max(c1, 1 + go(id1 + 1, id2 + 1));
    int c2 = go(id1 + 1, id2);
    int c3 = go(id1, id2 + 1);
    return ans = max({c1, c2, c3});
}

void find(int i, int j){
    if(i >= n || j >= m)
        return;

    int actual = go(i, j);

    int c1 = 0;
    if(s[i] == t[j]){
        c1 = 1 + go(i + 1, j + 1);
        if(actual == c1){
            cout << s[i];
            return find(i + 1, j + 1);
        }
    }

    int c2 = go(i + 1, j);
    if(actual == c2){
        return find(i + 1, j);
    }

    int c3 = go(i, j + 1);
    if(actual == c3){
        return find(i, j + 1);
    }
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 

    memset(dp, -1, sizeof(dp));
    cin >> s >> t;
    n = sz(s), m = sz(t);
    maxLen = go(0,0);
    find(0, 0);
}

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

using ll=long long; 

void solve(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(auto& e:a)cin>>e;
	int cur=1;
	for(auto e:a){
		if(e==cur)cur++;
	}
	if(cur==1){
		cout<<-1<<endl;
	}else{
		cout<<n-cur+1<<endl;
	}
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
        #define ll long long int
        using namespace std;
        #define mod 1000000007
        #define pb push_back
        #define fi first
        #define si second
        #define mp make_pair
        #define f(n) for(ll i=0;i<n;i++)
        #define ff(m) for(ll j=0;j<m;j++)
        #define fr(i,p,n) for(ll i=p;i<n;i++)
        #define in insert
        ll exp(ll a,ll b,ll m);
        #define vl vector<ll> 
        #define pll pair <ll,ll>
        void printpar(vector<int> graph[], int v, int s){
            bool marked[v+1];
            int par[v+1];
            f(v+1){
                par[i]=-1;
            }
            f(v+1)
            marked[i]=false;

            queue<int> q;
            q.push(s);
            par[s]=0;

            marked[s]=true;

            while(!q.empty()){
                s=q.front();
                q.pop();

                f(graph[s].size()){
                    int b=graph[s][i];
                    if(!marked[b]){
                        q.push(b);
                    par[b]=s;

                    marked[b]=true;
                    }
                }
            }
            bool ans=true;
            fr(i,1,v+1){
                if(par[i]==-1)
                    {   
                        ans=false;
                        cout<<"No"<<endl;}
            }
            if(ans){
                cout<<"Yes"<<endl;
                fr(i,2,v+1){
                    cout<<par[i]<<endl;
                }
            }

        }

    
        void solve(){
                
            int n,m;
            cin>>n>>m;
            vector<int> adj[n+1];
            int a,b;
            f(m){
                cin>>a>>b;
                adj[a].pb(b);
                adj[b].pb(a);
            }

            printpar(adj, n, 1);
        }
 
       int main()
       {
 
            int t=1;
             //cin>>t;
            while(t--)
               solve();
    
            return 0;
        }
 
        ll exp(ll a,ll b,ll m)
        {
            if(b==0)
            {
                return 1;
            }
            ll temp =exp(a,b/2,m);
            temp=(temp*temp)%m;
            if(b&1)
            {
                return (temp*(a%m))%m;
            }
            return temp;
        }

Measured memory_bytes: 10488
import java.util.Scanner;

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

        int sum = 0;
        for (int i = 0; i < n.length; i++) {
            sum += Integer.parseInt(n[i]);
        }

        if (sum%9 == 0) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 54340
k = int(input())

from collections import deque

count = 0
q = deque()
q.append(1)
q.append(2)
q.append(3)
q.append(4)
q.append(5)
q.append(6)
q.append(7)
q.append(8)
q.append(9)
li = []
while q:
    p = q.popleft()
    li.append(p)
    p = str(p)
    count += 1
    if count==10**5:
        break
    if p[-1]!="9" and p[-1]!="0":
        p = str(p)
        z = p + str(int(p[-1])-1)
        za = p + str(int(p[-1]))
        zb = p + str(int(p[-1])+1)
        q.append(int(z))
        q.append(int(za))
        q.append(int(zb))
    elif p[-1]=="9":
        z = p + str(int(p[-1])-1)
        za = p + str(int(p[-1]))
        q.append(int(z))
        q.append(int(za))
    elif p[-1]=="0":
        z = p + str(int(p[-1])+1)
        za = p + str(int(p[-1]))
        q.append(int(z))
        q.append(int(za))
li.sort()
print(li[k-1])



Measured memory_bytes: 57432
n = int(input())
a = n // 100
b = n % 100
if 1 <= a and a <=12:
    if 1 <= b and b <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1 <= b and b <= 12:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;

int main() {
    int N;
    int ans = INF;
    cin >> N;
    vector<int> x(N);
    vector<int> dp(N+1);
    dp[0] = 0;
    rep(i, N) {
        cin >> x[i];
    }
    for (int j = 1; j <= 100; j++) {
            int sum = 0;
        for (int i = 0; i < N; i++) {
            sum += (x[i] - j) * (x[i] - j);
        }
        if (ans > sum) {
            ans = sum; 
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// AtCoder template
// 見た奴全員saba!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    ll n; cin >> n;
    ll m; cin >> m;
    ll ans = 1LL;
    for(ll i = 1LL; i*i <= m; ++i){
        if(m%i == 0){
            if((m/i) >= n) ans = max(ans, i);
            if((m/(m/i)) >= n) ans = max(ans, m/i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#define MN 201000

int f[MN];
int h[MN], nxt[2 * MN], to[2 * MN], K = 0;
int ans = 1;

void ins(int u, int v) {nxt[++K] = h[u]; h[u] = K; to[K] = v;}

void dfs(int x, int fa)
{
	f[x] = 1;
	int Max = -1, cMax = -1;
	for(int i = h[x]; i; i = nxt[i])
	{
		if(to[i] == fa) continue;
		dfs(to[i], x);
		f[x] = std::max(f[x], f[to[i]] + 1);
		if(f[to[i]] >= Max) {cMax = Max; Max = f[to[i]];}
		else if(f[to[i]] >= cMax) cMax = f[to[i]]; 
	}
	ans = std::max(ans, Max + cMax + 1);
}

int main()
{
	int n; scanf("%d", &n);
	for(int i = 1; i < n; i++)
	{
		int x, y; scanf("%d%d", &x, &y);
		ins(x, y); ins(y, x);
	}
	dfs(1, 0);
	ans = std::max(ans, f[1]);
	puts(ans % 3 == 2 ? "Second" : "First");
}

Measured memory_bytes: 16896
#include<iostream>
using namespace std;
#define int long long int
int32_t main()
{
	int n,m;
	cin>>n>>m;
	int j;
	int sum=0;
	for(j=0;j<m;j++)
    {
		int x;
		cin>>x;
		sum+=x;
	}
	if(sum>n)
	  cout<<-1<<endl;
    else
      cout<<(n-sum)<<endl;
}


Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
#define TT std::tuple<int,int,int>
int H, W;
std::vector<int> one[1010][1010];
std::vector<TT> M;
int ans;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,-1,0,1 };
int map[1010][1010];
bool Q[1010][1010];
int main() {
	std::cin >> H >> W;
	for (int i = 0; i <= H + 1; i++) {
		for (int j = 0; j <= W + 1; j++) {
			if (i == 0 || j == 0 || i == H + 1 || j == W + 1) {
				map[i][j] = 1 << 30;
				continue;
			}
			std::cin >> map[i][j];
			M.emplace_back(TT{ map[i][j],i,j });
		}
	}
	std::sort(M.begin(), M.end());
	for (auto u : M) {
		int a, b, c;
		std::tie(a, b, c) = u;
		bool flag = 1;
		for (int i = 0; i < 4; i++) {
			int rx = b + dx[i];
			int ry = c + dy[i];
			if (map[rx][ry] < map[b][c]) {
				flag = false;
				if (Q[rx][ry]) {
					ans++;
					map[b][c] = true;
					break;
				}
				for (auto w : one[rx][ry]) {
					one[b][c].emplace_back(w);
				}
			}

		}
		if (flag)one[b][c].emplace_back(a);
		std::sort(one[b][c].begin(), one[b][c].end());
		one[b][c].erase(std::unique(one[b][c].begin(), one[b][c].end()), one[b][c].end());
		if (one[b][c].size() >= 2)ans++;
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 111116
from itertools import permutations
N,M,R=map(int,input().split())
r = [int(i) for i in input().split()]
inf=10**10
#[k][j][i]
dp=[[[inf]*N for i in range(N)]for i in range(N+1)]
for i in range(M):
    a,b,c=map(int,input().split())
    dp[0][a-1][b-1]=c
    dp[0][b-1][a-1]=c
for k in range(1,N+1):
    for j in range(N):
        for i in range(N):
            dp[k][j][i]=min(dp[k-1][j][i],dp[k-1][j][k-1]+dp[k-1][k-1][i])

ans =inf
for elem in permutations(r, R):
    dis=0
    for i in range(R-1):
        dis+=dp[N][elem[i+1]-1][elem[i]-1]
    ans=min(ans,dis)
print(ans)

Measured memory_bytes: 113628
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        int n; cin >> n;
        double a[n];
        for(int i = 0; i<n; i++){
            cin >> a[i];
        }
        sort(a,a+n);
            double res = (a[0]+a[1])/2;
            for(int i = 2; i<n; i++){
                res = (res+a[i])/2;
            }
        cout<<res<<endl;



return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

int main() {
	map<string, int>d;
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		d[s]++;
	}
	int m; cin >> m;
	for (int i = 0; i < m; i++) {
		string s; cin >> s;
		d[s]--;
	}

	int ans = 0;
	for (auto&& x : d) {
		ans = max(ans, x.second);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3516
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    string N;
    cin >> N;
 
    string ans = "No";
 
 
    for (int i = 0; i < 3; i++)
    {
        if (N.at(i) == '7')
        {
            ans = "Yes";
        }
        
    }
    
    cout << ans << endl;
   
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void) {
	int m,n;
	for(m = 1; m <= 9; m++){
		for(n = 1; n <= 9; n++){
			printf("%dx%d=", m,n);
			printf("%d\n", m*n);
		}
	}
	return 0;
}

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

int main(){
  int n;
  set<int> s;
  string ans="YES";
  cin>> n;
  for(int i=0; i<n; i++){
    int a;
    cin>> a;
    if(s.count(a)){
      ans="NO";
      break;
    }
    s.insert(a);
  }
  cout<< ans <<endl;
}

Measured memory_bytes: 12988
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, d;
int get(int i) {
    int cnt = 0;
    while ((i % 100) == 0) {
        cnt++;
        i /= 100;
    }
    return cnt;
}
main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (a > 8 || b > 8) cout << ":(";
    else cout << "Yay!";
    return 0;
}


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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
//#define int long long

signed main(){
    string s; cin >> s;
    bool ans = s[1]==s[2] && (s[0]==s[1] || s[2]==s[3]);
    cout << (ans ? "Yes" : "No") << endl;
}

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

typedef long long ll;
const int N = 4040, MOD = 1000 * 1000 * 1000 + 7;

int sum(int a, int b) {
	a += b;
	if(a >= MOD)
		a -= MOD;
	return a;
}

int mul(int a, int b) {
	return 1LL * a * b % MOD;
}

int n, k, c[N][N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	fill(c[0], c[0] + N, 1);
	for (int i = 1; i < N; i++)
		for (int j = 1; j < N; j++)
			c[i][j] = sum(c[i - 1][j - 1], c[i][j - 1]);
	cin >> n >> k;
	n -= k;
	for (int i = 1; i <= k; i++)
		cout << mul(c[i - 1][k - 1], c[i][n + 1]) << '\n';
	return 0;
}

Measured memory_bytes: 64000
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;
#define HERE cout<<"here"<<en
#define _out(value) cout<<"      "<<value<<en
#define out(value) cout<<value<<en

#define MAX 100005
int n,l,a[MAX];
int val[MAX];

int main(){
  cin>>n>>l;
  for(int i=1; i<=n; i++) cin>>a[i];
  a[0]=a[n+1]=0;
  for(int i=1; i<=n; i++) val[i]=INF;
  
  for(int i=1; i<=n; i++){
    if(val[i]==INF&&a[i]>a[i-1]&&a[i]>a[i+1]){
      val[i]=l-a[i];
      
      int nown=i;
      int rec=val[i];
      for(;;){
        nown++;
        if(a[nown]>a[nown+1]&&nown<=n){
          val[nown]=rec+l-a[nown];
          rec=val[nown];
        }else break;
      }
      
      nown=i;
      rec=val[i];
      for(;;){
        nown--;
        if(a[nown]>a[nown-1]&&nown>0){
          val[nown]=rec+l-a[nown];
          rec=val[nown];
        }else break;
      }
      i+=nown-i-1;
    }
  }
  
  for(int i=1; i<=n; i++){
    if(val[i]==INF){
      int c=max(val[i-1],val[i+1]);
      val[i]=c+l-a[i];
    }
  }
  
  int ans=0;
  for(int i=1; i<=n; i++){
    ans=max(ans,val[i]);
  }
  
  cout<<ans<<en
  RE
}



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

bool dp[100001];// true, false がそれぞれ勝ち、負け

int main(){
  int N;
  int K;
  int a[100];
  std::cin>>N>>K;
  for(int i=0;i<N;++i){
    std::cin>>a[i];
  }
  dp[0]=false;
  for(int i=1;i<=K;++i){
    bool ok=false;
    for(int j=0;j<N;++j){
      if(i-a[j]<0)continue;
      ok|=!dp[i-a[j]];
    }
    dp[i]=ok;
  }
  printf(dp[K]?"First\n":"Second\n");
  return 0;
}


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

int main(){
    int N = 0;
    int K = 0;
    cin >> N >> K;
    vector<int> h(N);
    int ans = 0;

    for(int i = 0; i < N; i++){
        cin >> h.at(i);
    }

    for(int i = 0; i < N; i++){
        if(h.at(i) >= K){
            ans ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(1e9+7)
using namespace std;

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a%b);
}
int lcm(int a, int b){
    return (a*b)/gcd(a,b);
}
int pow1(int x, unsigned int y) { 
    int temp; 
    if( y == 0) 
        return 1; 
    temp = pow1(x, y/2); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return ((x*temp)%mod*(temp)%mod)%mod; 
} 
int inv_mod(int a){
    int res = 1;
    int mod_temp = mod-2;
    while(mod_temp){
        if(mod_temp&1){
            res = ((res%mod)*(a%mod))%mod;
        }
        a = ((a%mod)*(a%mod))%mod;
        mod_temp >>= 1;
    }
    return res%mod;
}
int ncr(int n, int k){
    int res = 1;
    if ( k > n - k )
        k = n - k;

    for (int i = 0; i < k; ++i){
        res = ((res%mod)*((n - i)%mod))%mod;
        res = ((res%mod)*(inv_mod(i + 1)%mod))%mod;
    }
    return res%mod;
}
int fibonacci(int n){
    double phi = (1LL + sqrt(5))/(double)2;
    int nth_fib = round(pow(phi,n)/sqrt(5));
    return nth_fib;
}

signed main(){

    fastIO
    
    int n;cin >> n;
    cout << (n+1)/2;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int be(int a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod))%mod; else return (be(a,b/2,mod)*be(a,b/2,mod))%mod;}
const int mod = 1e9 + 7;
#define PI 3.14159265359
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcountll
#define setbitcnt __builtin_ctz
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
#define mkp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define roundup(a,b)  std::cout << std::fixed;std::cout << std::setprecision(b); std::cout << a
const int siz = (1e5 + 10);
const int logi = 21;
const double epsilon = 1e-6;
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}


signed main()
{
	#ifndef ONLINE_JUDGE
 	freopen("in.txt", "r", stdin);
 	freopen("out.txt", "w", stdout);
 	#else
// // online submission
 	#endif 
	speedrap
	int t;
	t = 1;
	//cin>>t;
	while(t--)
	{
		int k;
		cin>>k;
		string s;
		cin>>s;

		if(s.length() <= k)
		{
			cout<<s<<"\n";
			continue;
		}

		string g = "";

		for(int i = 0 ; i < k ; i++)
		{
			g.push_back(s[i]);
		}

		g.push_back('.');
		g.push_back('.');
		g.push_back('.');

		cout<<g<<"\n";
	}
}

Measured memory_bytes: 3656
N, x = map(int, input().split())
A = list(map(int, input().split()))
lowest_costs = A[:]
ans = float('inf')

for k in range(N):
    lowest_costs = [min(lowest_costs[i], A[i-k]) for i in range(N)]
    ans = min(sum(lowest_costs) + x * k, ans)

print(ans)

Measured memory_bytes: 3188
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
#define MAX 5100000
#define MOD 1000000007

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main(){
  init_io();
  ll n,m,k,ans=0;
  cin >> n >> m >> k;
  COMinit();
  for(ll i=0;i<n;i++){
    for(ll j=0;j<m;j++){
      ll tmp = n-i;
      tmp *= ((m-j)*(i+j))%MOD;
      tmp %= MOD;
      if(i!=0&&j!=0) tmp *= 2;
      tmp %= MOD;
      ans += tmp;
      ans %= MOD;
    }
  }
  ans *= COM(n*m-2,k-2);
  ans %= MOD;
  cout << ans << endl;
}


Measured memory_bytes: 119808
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int p[] = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
		}
		int a[] = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = p[i];
		}
		Arrays.sort(a);
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			if(p[i] != a[i]) {
				cnt++;
			}
		}
		if(cnt > 2) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long n,m,v[100009][3],ans=-(1LL<<60),i,j,k,s,tt;
int main(){
  cin>>n>>m;
  for(i=0;i<n;i++)for(j=0;j<3;j++)cin>>v[i][j];
  for(i=0;i<8;i++){
    vector<long>t;
    for(j=0;j<n;j++){
      s=0;
      for(k=0;k<3;k++){
        if((i>>k)&1)s+=v[j][k];
        else s-=v[j][k];
      }
      t.push_back(s);
    }
    sort(t.rbegin(),t.rend());
    tt=0;
    for(j=0;j<m;j++)tt+=t[j];
    ans=max(ans,tt);
  }
  cout<<ans<<endl;
  return 0;
}


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

int f(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}
	return ret;
}

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

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	rep(i, n) a[i] /= 2;
	int t = f(a[0]);
	rep(i, n) {
		if (f(a[i]) != t) {
			cout << 0 << endl;
			return 0;
		}
		a[i] >>= t;
	}
	m >>= t;
	ll l = 1;
	rep(i, n) {
		l = lcm(l, a[i]);
		if (l > m) {
			cout << 0 << endl;
			return 0;
		}
	}
	m /= l;
	cout << (m + 1) / 2 << endl;
	return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

vector<int> tpsort(vector<vector<int>>& G) {
    int V = G.size();
    vector<int> sorted_vertices;
    queue<int> que;
    vector<int> indegree(V);
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < G[i].size(); j++) {
            indegree[G[i][j]]++;
        }
    }
    for (int i = 0; i < V; i++) {
        if (indegree[i] == 0) {
            que.push(i);
        }
    }
    while (que.empty() == false) {
        int v = que.front();
        que.pop();
        for (int i = 0; i < G[v].size(); i++) {
            int u = G[v][i];
            indegree[u] -= 1;
            if (indegree[u] == 0) que.push(u);
        }
        sorted_vertices.push_back(v);
    }
    return sorted_vertices;
}

int main() {
    ll n;
    cin >> n;
    vector<vector<double>> z(n+1,vector<double>(n+1));
    z[0][0] = 1.0;
    for (int i = 0; i < n; i++) {
        double p;
        cin >> p;
        for (int j = 0; j < n; j++) {
            z[i + 1][j] += (1.0 - p) * z[i][j];
            z[i + 1][j + 1] += p * z[i][j];
        }
    }
    double ans = 0.0;
    for (int i = n/2+1; i < n+1; i++) {
        ans += z[n][i];
    }
    cout <<fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 73680
#include<iostream>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int i=0,count=0;
    while(s[i]!='\0')
    {
        if(s[i]!=t[i])
            count++;
        i++;
    }
    cout<<count<<endl;
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int tmp=0;
  int cnt=1;
  int A[N];
  
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  
  for(int i=0;i<N;i++){
    if(A[i]==cnt){
      cnt++;
    }else{
      tmp++;
    }
  }
  
  
  if(cnt==1){
    cout << "-1" << endl;
  }else{
    cout << tmp << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL N; cin >> N;
    vector<LL> a(N);
    REP(i,N) cin >> a[i];
    LL ans = LINF;

    for(int i = -100; i <= 100; i++)
    {
        LL tmp=0;
        REP(j,N)
        {
            tmp += int(pow(a[j]-i,2));
            dump(j)
        }
        if(tmp < ans) ans = tmp;

    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;



void solve(long long A, long long B, long long K){
    if(A+B<=K){
        cout<<"0 0"<<endl;
    }else if(A<K){
        cout<<"0 "<<B-(K-A)<<endl;
    }else{
        cout<<A-K<<" "<<B<<endl;
    }
}

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


Measured memory_bytes: 3756
#include <stdio.h>
#define min(a, b) ((a) < (b) ? (a) : (b))

int main(){
  int n,a,b;
  scanf("%d%d%d",&n,&a,&b);

  printf("%d ",min(a,b));

  if(a+b-n>0){
    printf("%d",a+b-n);
  }else{
    printf("0");
  }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    string S,T;
    cin>>S>>T;
    int x=S.length();
    rep(i,x){
        if(S[i]!=T[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int s, i, j, k;
	vector<int> a(5), g(5);
	s = 0;
	for (i = 0; i < 5; i++) {
		cin >> a[i];
		if (a[i] % 10 == 0) g[i] = 0;
		else g[i] = 10 - (a[i] % 10);
		s += a[i] + g[i];
	}
	sort(g.rbegin(), g.rend());
	s -= g[0];

	cout << s << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#define ll long long
using namespace std;
const int maxn=1e5+10;
const int mod=1000000007;
char a[55];

int main()
{
    ll ans=1;
    int n;
    scanf("%d",&n);
    scanf("%s",a);
    scanf("%s",a);
    if(n==1)
        cout<<3<<endl;
    else
    {
        int tag1=0,tag2=0,tag=1;
        for(int i=0; i<n; i++)
        {
            if(a[i]==a[i+1])
            {
                if(tag)
                {
                    ans=ans*6%mod;
                    tag=0;
                    i++;
                    tag2=0;
                    tag1=1;
                }
                else
                {
                    if(tag1)
                        ans=ans*3%mod;
                    else
                    {
                        ans=ans*2%mod;
                        tag1=1;
                    }
                    i++;
                    tag2=0;
                }
            }
            else if(a[i]!=a[i+1])
            {
                //cout<<"s"<<endl;
                if(tag)
                {
                    ans=ans*3%mod;
                    tag=0;
                    tag2=1;
                }
                else
                {
                    tag1=0;
                    if(tag2)
                        ans=ans*2%mod;
                    if(tag2==0)
                        tag2=1;
                }
            }
           // cout<<ans<<" "<<tag1<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}
//52
//Rvvttd
//WIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
//RLLwwd
//WIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn


Measured memory_bytes: 256
#include <iostream>
#include <stdint.h>

int main(void)
{
    int n;
    std::cin >> n;

    int64_t l[100];
    l[0] = 2;
    l[1] = 1;
    for (int i = 2; i <= n; ++i)
    {
        l[i] = l[i - 2] + l[i - 1];
    }
    std::cout << l[n] << std::endl;
    return 0;
}


Measured memory_bytes: 384
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

int a[200010],b[200010],c[200010][3];

int main()
{
	int n;scanf("%d",&n);n=2*n-1;
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int l=1,r=n;
	while (l<=r)
	{
		int mid=(l+r)>>1;
		for (int i=1;i<=n;i++) if (a[i]<=mid) b[i]=1; else b[i]=0;
		int l0=1,m=0;
		for (int i=2;i<=n+1;i++)
			if (i==n+1||b[i]!=b[i-1])
			{
				if (i-l0>1) {c[++m][0]=l0;c[m][1]=i-1;c[m][2]=b[l0];}
				l0=i;
			}
		int t;
		if (!m)
			t=b[(n+1)/2]^(n/2%2);
		else
		{
			int ma=n,x=(n+1)/2;
			for (int i=1;i<=m;i++)
			{
				if (abs(c[i][0]-x)<ma) {ma=abs(c[i][0]-x);t=c[i][2];}
				if (abs(c[i][1]-x)<ma) {ma=abs(c[i][1]-x);t=c[i][2];}
			}
		}
		if (t) r=mid-1; else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}


Measured memory_bytes: 2304
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N;
    cin >> N;

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

    bitset<24> B(0);
    long long sum = 0;
    long long ans = 0;

    int right = 0;
    for (int left = 0; left < N; left++) {
        if (right <= left) right = left;
        while (right < N && (sum + A[right]) == (B ^ (bitset<24>(A[right]))).to_ullong()) {
            sum += A[right];
            B ^= bitset<24>(A[right]);
            right++;
        }
        ans += (right - left);
        sum -= A[left];
        B ^= A[left];
    }

    cout << ans << endl;

    return 0;
}














































Measured memory_bytes: 1152
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    print(n * (n - 1) // 2 + m * (m - 1) // 2)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38384
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

Measured memory_bytes: 3624
input_line = input().rstrip()

num753 = 753

for i in range(len(input_line)):
    if i + 3 <= len(input_line):
        num3 = str(input_line[i]) + str(input_line[i+1]) + str(input_line[i+2])
    #print(num3)
    if num753 > abs(753 - int(num3)):
        num753 = abs(753 - int(num3))
    if i+3 == len(input_line):
        break
print(num753)

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

int main() {
	int	N;
	cin >> N;
	vector<int> vec(N);
	rep(i, N)
		cin >> vec.at(i);
	int	M;
	cin >> M;
	rep(i, M)
	{
		int	a;
		cin >> a;
		cout << binary_search(vec.begin(), vec.end(), a) << endl;
	}
}



Measured memory_bytes: 3096
#!/usr/bin/env python3

from bisect import bisect_right

def main():
    s = input()
    t = input()
    indices = [[] for i in range(26)]
    n = len(s)
    for i in range(n):
        c = s[i]
        ic = ord(c) - ord("a")
        indices[ic].append(i)
    for i in range(26):
        if not indices[i]:
            continue
        indices[i].append(indices[i][0] + n)

    ptr = -1
    for c in t:
        ic = ord(c) - ord("a")
        if len(indices[ic]) == 0:
            print(-1)
            return
        nptr = bisect_right(indices[ic], ptr % n)
        ptr += indices[ic][nptr] - (ptr % n)

    print(ptr + 1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 45680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
    int n;cin>>n;
    vector<int> a(n,0);
    REP(i,n){
        cin>>a[i];
    }
   sort(a.begin(),a.end());
    cout<<a[n-1]-a[0]<<endl;}


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

int main() {
  int K;
  cin>>K;
  if(K==1){
    cout<<"1";
}
 else if(K==2){
    cout<<"1";
}
else if(K==3){
    cout<<"1";
}
  else if(K==4){
    cout<<"2";
}
  else if(K==5){
    cout<<"1";
}
 else if(K==6){
    cout<<"2";
}
  else if(K==7){
    cout<<"1";
}
  else if(K==8){
    cout<<"5";
}
 else if(K==9){
    cout<<"2";
}
  else if(K==10){
    cout<<"2";
}
  else if(K==11){
    cout<<"1";
}
  else if(K==12){
    cout<<"5";
}
  else if(K==13){
    cout<<"1";
}
  else if(K==14){
    cout<<"2";
}
  else if(K==15){
    cout<<"1";
}
  else if(K==16){
    cout<<"14";
}
 else if(K==17){
    cout<<"1";
}
 else if(K==18){
    cout<<"5";
}
  else if(K==19){
    cout<<"1";
}
  else if(K==20){
    cout<<"5";
}
  else if(K==21){
    cout<<"2";
}
  else if(K==22){
    cout<<"2";
}
  else if(K==23){
    cout<<"1";
}
  else if(K==24){
    cout<<"15";
}
 else if(K==25){
    cout<<"2";
}
 else  if(K==26){
    cout<<"2";
}
  else if(K==27){
    cout<<"5";
}
  else if(K==28){
    cout<<"4";
}
  else if(K==29){
    cout<<"1";
}
  else if(K==30){
    cout<<"4";
}
  else if(K==31){
    cout<<"1";
}
 else{
    cout<<"51";
 }
}


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

int main(){
    string str;
    int n;
    
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        int max=0,min=0;
        int tmp_max[8],tmp_min[8];
        
        cin >> str;
        for(int i = 0 ; i < 8 ; i++) tmp_min[i] = str[i] - '0';
        
        sort(tmp_min,tmp_min+8);
        
        for(int i = 0 ; i < 8 ; i++) tmp_max[i] = tmp_min[7-i];
        
        int num = 10000000;
        for(int i = 0 ; i < 8 ; i++){
            max += tmp_max[i] * num;
            min += tmp_min[i] * num;
            num /= 10;
        }
        
        cout << max - min << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int X,Y;
    cin >> X >> Y;
    if(X%Y == 0) {
        cout << -1 << endl;
    }
    else {
        cout << X << endl;
    }
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

int main(){
  int n; li k; cin >>n >>k;
  vector<int> a(n),seen(n,-1);
  rep(i,n){
    cin >>a[i];
    a[i]--;
  }

  int ord=1,c=0,tail;
  rep(i,n+1){
    if(seen[c]>=0){
      ord=i-seen[c];
      tail=seen[c];
      break;
    }
    seen[c]=i;
    c=a[c];
  }
  if(df)print(ord,tail,seen);
  if(k>tail) k=(k-tail)%ord+tail;
  c=0;
  rep(i,k){
    c=a[c];
  }
  print(c+1) ;
}


Measured memory_bytes: 4784
n, m = map(int, input().split())

edges = []
for i in range(m):
    a, b, w = map(int, input().split())
    edges.append((a-1, b-1, w))

init_val = -10 ** 9 * 1000
d = [init_val] * n
d[0] = 0
for _ in range(n):
    updated = False
    for a, b, w in edges:
        if d[a] != init_val and d[b] < d[a] + w:
            d[b] = d[a] + w
            updated = True
    if not updated:
        break
if updated: #閉路の存在
     for a, b, w in edges:
        if d[a] != init_val and d[b] < d[a] + w:
            d[b] = d[a] + w
            if b == n - 1:
                print('inf')
                quit()
print(d[n-1])


Measured memory_bytes: 79680
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
void Yes() { cout << "Yes\n"; }
void No() { cout << "No\n"; }

int n, k, w[100000];

bool check(int p) {
	int j = 0, sum;
	for (int i = 0; i < k; ++i) {
		sum = 0;
		while (j < n && sum + w[j] <= p) {
			sum += w[j];
			j++;
		}
	}

	if (j == n)
		return true;
	else
		return false;
}

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
		cin >> w[i];

	int l = 0, r = INF, mid;
	while (r - l > 1) {
		mid = (l + r) / 2;
		if (check(mid))
			r = mid;
		else
			l = mid;
	}

	cout << r << endl;

	return 0;
}

Measured memory_bytes: 3504
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int time = Integer.parseInt(br.readLine());
        long sum = 0;
        int max = -1000000;
        int min = 1000000;
        int num[] = new int[time];
        String[] ary = br.readLine().split(" ");
        
        for (int i = 0; i < time; i++) {
            num[i] = Integer.parseInt(ary[i]);
            sum += num[i];
            if (max < num[i]) {
                max = num[i];
            }
            
            if (min > num[i]) {
                min = num[i];
            }
        }
        
        System.out.println(min + " " + max + " " + sum);
        
    }
}

Measured memory_bytes: 28144
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

long long a,b;

int main() {
	double c;
	std::cin>>a>>c;
	b=(c*100+0.5);
	std::cout<<a*b/100;
	return 0;
}

Measured memory_bytes: 3696
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

int main(){
	int q,x;
	list<int> v;
	char com[20];
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%s",com);
		if(com[0]=='i'){
			scanf("%d",&x);
			v.push_front(x);
		}else if(com[6]=='L'){
			v.pop_back();
		}else if(com[6]=='F'){
			v.pop_front();
		}else if(com[0]=='d'){
			scanf("%d",&x);
			for(list<int>::iterator it = v.begin();it!=v.end();it++){
				if(*it==x){
					v.erase(it);
					break;
				}
			}
		}
	}
	
	int i =0;
	for(list<int>::iterator it =v.begin();it!=v.end();it++){
		if(i++)	printf(" ");
		printf("%d",*it);
	} 
	printf("\n");
	
	return 0;
}




Measured memory_bytes: 34380
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;



int main(){
    int k, a, b;
    cin >> k >> a >> b;
    bool f = false;

    int i = 1;
    while(k * i <= b){
        if(k * i >= a){
            f = true;
            break;
        }
        i++;
    }
    cout << (f ? "OK" : "NG") << endl;
}



Measured memory_bytes: 3132
def main():
    n, m = list(map(int, input().split()))
    root_start = []
    root_goal = []
    ans = {}
    for i in range(m):
        li = list(map(int, input().split()))
        if li[0] == 1:
            ans.setdefault(li[1], 0)
            ans[li[1]] += 1
        elif li[1] == n:
            ans.setdefault(li[0], 0)
            ans[li[0]] += 1
    flg = False
    for k in ans:
        if ans[k] >= 2:
            flg = True

    print('POSSIBLE') if flg else print('IMPOSSIBLE')



if __name__ == '__main__':
    main()


Measured memory_bytes: 27088