akhauriyash/Code-Regression huggingface dataset:
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

k=int(input())
n=len(input())
ans=0
for i in range(k,-1,-1):
  ans=(ans+cmb(k+n,i)*pow(25,i,mod))%mod
print(ans)

Measured memory_bytes: 222924
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

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

    s.replace(3, 1, "8");
    std::cout<<s<<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N=1000006;
using namespace std;
int n,cnt[3],mn,tb,tc,
b0,b1,c0,c1,i,j,al,ti;
char S[N];
bool del[N];
void print(){
	for(i=1;i<n;i++)
	cerr<<(char)(S[i]+65);
	cerr<<endl;
}
inline void reb(){
	al=n,n=0;
	for(i=1;i<al;i++)
	if(S[n]^S[i]&&!del[i])
	S[++n]=S[i];
	al=0,S[++n]=-1;
	for(i=0;i<=n;i++)del[i]=0;
}
inline bool chk(int x){
	return S[x]==tb||S[x]==tc;
}
int main(){
	scanf("%s",S+1),n=strlen(S+1)+1;
	S[0]=-1,reb();
	for(i=1;i<n;i++)
	cnt[S[i]-='A']++;
	if(cnt[0]&&cnt[1]&&cnt[2]);
	else return 0;
	for(i=1;i<3;i++)
	cnt[mn]>cnt[i]?mn=i:0;
	tb=!mn,tc=3^mn^tb;
	//print();
	for(i=1,j;i<=n;i++)
	if(S[i]!=tb&&S[i]!=tc){
		for(j=i-1;S[j]==tb||S[j]==tc;j--);
		if(i-j>2)b0++,c0++;
		else if(i-j>1){
			S[i-1]==tb?b0++:c0++;
			if(S[j]==mn&&S[i]==mn)
			S[i-1]==tb?b1++:c1++;
		}
	}
	if(c0<b1)swap(c0,b0),swap(c1,b1),swap(tb,tc);/*
	cerr<<mn<<","<<"("<<tb<<":"<<b0<<','<<b1<<")("<<
	tc<<":"<<c0<<','<<c1<<")\n";*/
	ti=max(0,c1-b0),c1-=ti;
	for(i=1,j;i<n&&ti;i++)
	if(S[i]!=tb&&S[i]!=tc){
		for(j=i-1;chk(j);j--);
		if(i-j==2&&S[j]==mn&&S[i]==mn
		&&S[j+1]==tc)del[i]=1,ti--;
	}
	reb(),b0=c0=0;
	for(int i=1;i<n;i++)
	if(S[i]==tb)b0++;else if(S[i]==tc)c0++;
	if(c0<b0)swap(c0,b0),swap(tb,tc);/*
	cerr<<mn<<","<<"("<<tb<<":"<<b0<<")("<<
	tc<<":"<<c0<<")\n";
	print();*/
	ti=c0-b0;
	for(int i=1;i<n&&ti;i++)
	if(S[i]==tc&&S[i-1]!=S[i+1])
	del[i]=1,ti--;
	assert(!ti);
	reb();
	//print();
	ti=0;
	for(int i=1;i<n;i++)
	S[i]==mn?ti--:(S[i]==tb?ti++:0);
	//cerr<<ti<<"???\n";
	assert(ti>=0);
	bool lst=0;
	for(int i=1;i<n&&ti;i++)
	if(chk(i)&&chk(i+1)&&(S[i+2]!=mn||!lst)&&!del[i])
	del[i]=del[i+1]=1,ti--;
	else if(S[i]==mn)lst=1;
	reb();
	for(int i=1;i<n;i++)
	putchar(S[i]+'A');
}

Measured memory_bytes: 3200
//tanzim bin nasir
#include<bits/stdc++.h>
typedef long long ll;
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    else
    gcd(b,a%b);
}
ll lcd(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
int main()
{
    ll a,b,t;
    cin>>a>>b>>t;
    if(a%b==0)
    cout<<a/b*t<<endl;
    else
    cout<<((a/b)+1)*t<<endl;
}



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

using namespace std;

int main() {
	vector<int> A(3);
	int sum = 0;
	for (int i = 0; i < 3; i++) {
		cin >> A[i];
		sum = max(sum, A[i]);
	}
	
	int K;
	cin >> K;
	for (int i = 0; i < K; i++) {
		sum *= 2;
	}

	sort(A.begin(), A.end());
	cout << sum + A[0] + A[1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include<random>
#include<iostream>
using namespace std;

int N, T;
int cost[3000];
int point[3000];

int visited[3002][3002][2];
int memo[3002][3002][2];

int dp(int dish, int c, int f) {
	if (visited[dish][c][f] == 1) {
		return memo[dish][c][f];
	}
	if (dish == N + 1) {
		memo[dish][c][f] = 0;
		visited[dish][c][f] = 1;
		return 0;
	}
	int ret = 0;
	if (f == 1) {
		ret = max(ret, point[dish] + dp(dish + 1, c, 0));
	}
	if (c >= cost[dish]) {
		ret = max(ret, point[dish] + dp(dish + 1, c - cost[dish], f));
	}
	ret = max(ret, dp(dish + 1, c, f));
	memo[dish][c][f] = ret;
	visited[dish][c][f] = 1;
	return memo[dish][c][f];
}

int main() {
	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		cin >> cost[i] >> point[i];
	}
	for (int i = 0; i < N+1; i++) {
		for (int j = 0; j < T+1; j++) {
			visited[i][j][0] = 0;
			visited[i][j][1] = 0;
		}
	}
	cout << dp(0, T - 1, 1);
}

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

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        int n = ipar();
        ntok();
        int[] arr = iapar(n-1);
        int sum = 0;
        for (int i = 0; i < n-2; i++)
        {
            sum += Math.min(arr[i], arr[i+1]);
        }
        sum += arr[0];
        sum += arr[n-2];
        out.println(sum);

        out.flush();
        in.close();
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public int[] iapar(int n)
    {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = ipar();
        }
        return arr;
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public long[] lapar(int n)
    {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = lpar();
        }
        return arr;
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

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


Measured memory_bytes: 21204
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int a, b; cin >> a >> b;

	int x = a + b;
	int y = max(x, a - b);
	int z = max(y, a*b);
	cout << z << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
int n,m;
int a,b;
cin>>n>>m;
vector<int>v;
for(int i=0;i<m;i++){
    cin>>a>>b;
    v.push_back(a);
    v.push_back(b);

}
int cnt=0;
int array[60];
for(int i=1;i<=n;i++){
    cnt=0;
    for(int j=0;j<v.size();j++){
        if(v[j]==i)cnt++;


}
array[i-1]=cnt;
}
for(int i=0;i<n;i++){
    cout<<array[i]<<endl;
}
    return 0;
}

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

int main() {
    int x, y; cin >> x >> y;
    bool flag = false;
    for (int i = 0; i <= x; i++) {
        int sum = i * 2 + 4 * (x-i);
        if (sum == y) flag = true;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
//#define MXN 300000
#define N 100005
int main(){
    vector<int> v[100005];
    int r[100005];
    fill(r,r+100005,0);
    r[1]=1;
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i = 1;i<=n;i++)
        v[i].pb(i);
    for(int i=0;i<m;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        int a=v[x].back();
        v[x].pop_back();
        if(v[y].size()&&r[v[y][0]])r[a]=1;
        if(r[a])
        for(int j =(int)v[y].size()-1;j>=0;j--){
            if(r[v[y][j]]==0)r[v[y][j]]=1;
            else break;
        }
        v[y].pb(a);
    }
    int ans=0;
    for(int i = 1;i<=n;i++){
        if(v[i].size()&&r[v[i][0]])ans++;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 6780
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline int read(){
	int x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    write(a); puts("");
}
int n,m,tong[1000],ji,he;
string s;
int main(){
    n=read(); m=read();
    for(int i=1;i<=n;i++){
    	cin>>s;
    	for(int j=0;j<m;j++)tong[s[j]]++;
	}
	for(int i='a';i<='z';i++)if(tong[i]&1)ji++; else if(tong[i]%4==2)he++;
	if((n&1)&&(m&1)){
		if(ji!=1){
			puts("No"); return 0;
		}
		if(he*2>n+m-2||((n+m-2-he*2)&3)){
			puts("No"); return 0;
		}else puts("Yes");
	}else if(!(n&1)&&!(m&1)){
		if(ji||he){
			puts("No"); return 0;
		}else puts("Yes");
	}else{
		if(n&1)swap(n,m);
		if(ji||he*2>n||(((n-he*2)&3))){
			puts("No"); return 0;
		}else puts("Yes");
	}
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

bool is_kaibun(string& s) {
  string s_r = s;
  reverse(s_r.begin(), s_r.end());
  return s == s_r;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = a; i <= b; i++) {
    string s = to_string(i);
    if (is_kaibun(s)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
four = 0
one = 0
even = 0
ans = 'No'
for x in a:
    if x % 4 == 0:
        four += 1
    elif x % 2 == 1:
        one += 1
    else:
        even += 1
if even == 0:
    if one <= four + 1:
        ans = 'Yes'
elif one <= four:
    ans = 'Yes'
print(ans)


Measured memory_bytes: 15020
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int GCD(int x, int y) {
    if (x % y == 0) return y;
    return GCD(y, x % y);
}

int main() {
    int K;
    cin >> K;
    int ans = 0;
    REP(i, K + 1) REP(j, K + 1) REP(k, K + 1) {
        ans += GCD(GCD(i, j), k);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
#include<iostream>
#define LL long long
#define N 1e9
using namespace std;
const int maxn = 3e5 + 5;
namespace SGT {
	struct node {
		LL mn, add;
		int ch[2];
	}t[maxn * 32];
	int cnt, root;
	int Create(int l, int r) {
		return t[++cnt] = (node) {l, 0, 0, 0}, cnt;
	}
	void push_up(int rt, int l, int r) {
		int mid = l + r >> 1;
		if(!t[rt].ch[0]) t[rt].ch[0] = Create(l, mid);
		if(!t[rt].ch[1]) t[rt].ch[1] = Create(mid + 1, r);
		t[rt].mn = min(t[t[rt].ch[0]].mn, t[t[rt].ch[1]].mn);
	}
	void push_down(int rt, int l, int r) {
		if(t[rt].add) {
			int mid = l + r >> 1, *ls = &t[rt].ch[0], *rs = &t[rt].ch[1];
			if(!*ls) *ls = Create(l, mid);
			if(!*rs) *rs = Create(mid + 1, r);
			t[*ls].add += t[rt].add, t[*ls].mn += t[rt].add;
			t[*rs].add += t[rt].add, t[*rs].mn += t[rt].add;
			t[rt].add = 0;
		}
	}
	LL Q(int l, int r, int tl, int tr, int & rt = root) {
		if(!rt) rt = Create(tl, tr);
		if(l == tl && r == tr) 
			return t[rt].mn;
		int mid = tl + tr >> 1;
		push_down(rt, tl, tr);
		if(r <= mid) return Q(l, r, tl, mid, t[rt].ch[0]);
		else if(l > mid) return Q(l, r, mid + 1, tr, t[rt].ch[1]);
		else return min(Q(l, mid, tl, mid, t[rt].ch[0]), Q(mid + 1, r, mid + 1, tr, t[rt].ch[1]));
	}
	void add(int l, int r, int tl, int tr, LL dt, int & rt = root) {
		if(!rt) rt = Create(tl, tr);
		if(tl == l && tr == r) 
			return t[rt].add += dt, t[rt].mn += dt, void();
		int mid = tl + tr >> 1;
		push_down(rt, tl, tr);
		if(r <= mid) add(l, r, tl, mid, dt, t[rt].ch[0]);
		else if(l > mid) add(l, r, mid + 1, tr, dt, t[rt].ch[1]);
		else add(l, mid, tl, mid, dt, t[rt].ch[0]), add(mid + 1, r, mid + 1, tr, dt, t[rt].ch[1]);
		push_up(rt, tl, tr);
	}
}
int n, a[maxn];
LL ans;
signed main() {
	scanf("%d", &n);
	for(register int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for(register int i = 1; i <= n; ++i) {
		ans += SGT :: Q(a[i], N, 0, N) - a[i];
		SGT :: add(0, a[i] - 1, 0, N, 1);
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 108416
from itertools import product

N, M = map(int, input().split())
abc = [[int(x) for x in input().split()] for _ in range(M)]

dist = [[float('inf') for _ in range(N)] for _ in range(N)]
for a, b, c in abc:
    dist[a - 1][b - 1] = c
    dist[b - 1][a - 1] = c

for k, i, j in product(range(N), repeat=3):
    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

ans = 0
for a, b, c in abc:
    if dist[a - 1][b - 1] != c:
        ans += 1
print(ans)

Measured memory_bytes: 3700
#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 <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()

int main() {
	int n;
	cin >> n;
	cout << n / 3600 << ":" << (n / 60) % 60 << ":" << n % 60 << endl;

	return 0;
}


Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  ll n,m;
  cin>>n>>m;
  ll ans=min(m/2,n);
  n-=ans;
  m-=ans*2;
  if(n)
    cout<<ans<<endl;
  else
    cout<<ans+m/4<<endl;
}


Measured memory_bytes: 384
def main():
    a,v = map(int,input().split())
    b,w = map(int,input().split())
    t = int(input())
    d = abs(b-a)
    u = v-w
    if u<=0:
        print('NO')
    else:
        if d/u>t:
            print('NO')
        else:
            print('YES')
    
if __name__ == "__main__":
    main()


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

int main(){
  int c[3][3];
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> c[i][j];
    }
  }

  int a[3] = {0}, b[3] = {0};
  a[0] = 0;
  b[0] = c[0][0] - a[0];
  a[1] = c[1][0] - b[0];
  b[1] = c[1][1] - a[1];
  a[2] = c[2][1] - b[1];
  b[2] = c[2][2] - a[2];
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      if(c[i][j] != a[i] + b[j]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	private static int[][] a;
	private static int[] color;
	private static int dist[];
	private static boolean visited[];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		a = new int[n][n];
		sc.nextLine();
		for (int i = 0; i < n; i++) {
			char[] s = sc.nextLine().toCharArray();
			for (int j = 0; j < s.length; j++) {
				if (i == j) {
					a[i][j] = 0;
				} else if (s[j] == '1') {
					a[i][j] = 1;
				} else {
					a[i][j] = 1000000;
				}
			}
		}

		color = new int[n];
		for (int i = 0; i < n; i++) {
			if (color[i] == 0) {
				if (!isBipartite(i, 1)) {
					System.out.println(-1);
					return;
				}
			}
		}

		//for (int i = 0; i < n; i++) {
		//	for (int j = 0; j < n; j++) {
		//		System.out.print(a[i][j]);
		//		System.out.print(" ");
		//	}
		//	System.out.println();
		//}


		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					if (a[i][k] >= 1000000 || a[k][j] >= 1000000) continue;
					if (a[i][j] > a[i][k] + a[k][j]) {
						a[i][j] = Math.min(a[i][j], a[i][k] + a[k][j]);
					}
				}
			}
		}

		//for (int i = 0; i < n; i++) {
		//	for (int j = 0; j < n; j++) {
		//		System.out.print(a[i][j]);
		//		System.out.print(" ");
		//	}
		//	System.out.println();
		//}

		int answer = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (a[i][j] < 1000000) {
					answer = Math.max(answer, a[i][j]);
				}

			}
		}

		System.out.println(answer + 1);
	}


	private static boolean isBipartite(int v, int c) {
		color[v] = c;
		for (int i = 0; i < a[v].length; i++) {
			if (a[v][i] != 1000000 && a[v][i] != 0) {
				if (color[i] == c) return false;
				if (color[i] == 0 && !isBipartite(i, -c)) return false;
			}
		}

		return true;
	}
}


Measured memory_bytes: 26196
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
#define inf 1000000000000001
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n=11;
    vector<ll> v(11,0);
    ll i,k;
    v[0]=26;
    for(i=1;i<11;i++)
    {
        v[i]=pow(26,i+1)+v[i-1];
    }
    //cout<<v[6];
    cin>>k;
    ll p;
    char a='a',ch;
    string s;
    ll size=lower_bound(v.begin(),v.end(),k)-v.begin()+1;
    for(i=0;i<size;i++)
    {
        p=k%26;
        if(p==0)
        {
            s.pb('z');
            k/=26;
            k=k-1;
        }
        else
        {
        ch=char(a+p-1);
        s.pb(ch);
        k/=26;
        }
    }
    reverse(s.begin(),s.end());
    cout<<s;
    return 0;
     
}

Measured memory_bytes: 4052
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int max(int a,int b){return (a>b ? a:b);}
int min(int a,int b){return (a<b ? a:b);}
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
//qsort(配列, 長さ, sizeof(int), compare_int);
double BS(int array[],int len,int target);

int N;
int L[110];

int main(){
    scanf("%d",&N);
    int sum = 0;
    int M = 0;;
    for(int i = 0;i < N;i++){
        scanf("%d",&L[i]);
        if(M < L[i]){
            M = L[i];
        }
        sum += L[i];
    }
    sum -= M;
    if(M < sum){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

double BS(int array[],int len,int target){ //(配列,長さ,見つける値)
    int low,mid,high;

    low = 0;
    high = len-1;

    int mark;

    while(low <= high){
        mid = (low + high) / 2;
        if(array[mid] == target){
            mark = 0;
            break;
        }else if(array[mid] < target){
            low = mid + 1;
            mark = 1;
        }else{
            high = mid - 1;
            mark = -1;
        }
    }
    if(mark == 0){
        return mid; //配列の何番目か（０から）
    }else if(mark == 1){
        return (double)mid + 0.5;//なかったらどこのあいだか
    }else{
        return (double)mid - 0.5;
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=205,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,M;cin>>N>>M;
        if(N==0&&M==0) break;
        vector<pair<int,int>> S(N);
        int sum=0;
        for(int i=0;i<N;i++){
            cin>>S[i].first>>S[i].second;
            sum+=S[i].first*S[i].second;
        }
        
        sort(all(S),[](pair<int,int> a,pair<int,int> b){
            return a.second>b.second;
        });
        
        for(int i=0;i<N;i++){
            if(M>=S[i].first){
                M-=S[i].first;
                sum-=S[i].first*S[i].second;
            }else if(M>0){
                sum-=M*S[i].second;
                M=0;
            }
        }
        
        cout<<sum<<endl;
    }
    
    
}






Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define PI 3.1415926536
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    double r;
    cin >> r;
    printf("%4.10f\n", 2*r*PI);

}



Measured memory_bytes: 3784
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = map(int,input().split())
    print(min(n%k,-n%k))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
import itertools
n = int(input())
c1 = tuple(map(int, input().split()))
c2 = tuple(map(int, input().split()))
a = []
for i in range(1,n+1):
    a.append(i)
b = sorted(list(itertools.permutations(a)))
for i in range(len(b)):
    if b[i] == c1:
        d = i
    if b[i] == c2:
        e = i
print(abs(d-e))

Measured memory_bytes: 8308
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef double keytype;

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int main(){
    int s;
    int a[1000000];

    scanf("%d", &s);

    a[0] = s;
    for(int i = 0; i < 1000000; ++i){
        //printf("%d\n", a[i]);
        if(a[i] % 2 == 0){
            a[i+1] = a[i] / 2;
            //printf("%d\n", a[i]);
        }else{
            a[i+1] = 3 * a[i] + 1;
            //printf("%d\n", a[i]);
        }
    }
    //printf("%d\n", a[4]);

    for(int i = 0; i < 1000000; ++i){
        for(int j = i+1; j< 1000000; ++j){
            if(a[i] == a[j]){
                int ans = j + 1;
                printf("%d\n", ans);
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 5608
import java.util.Scanner;

public class Main {

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

    int sum = 0;
    for (int i = 0; i < 3; i++) {
      sum += sc.nextInt();
    }

    if (sum >= 22) {
      System.out.println("bust");
      return;
    }

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


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

using ll = long long;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (ll i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (ll i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

template<typename T> using pop_max = std::priority_queue<T>;
template<typename T> using pop_min = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T> void LOG(const T& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T> void LOG(const vector<vector<T>>& a) { for (const auto& x : a) LOG(x); }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

ll ceil(ll a, ll b) { return a > 0 ? (a - 1) / b + 1 : a / b; }
ll gcd(ll a, ll b) { while (b != 0) { ll t = b; b = a % b; a = t; } return a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll gcd(const vector<ll>& v) { return accumulate(v.begin(), v.end(), 1LL, static_cast<ll(*)(ll, ll)>(gcd)); }
ll lcm(const vector<ll>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<ll(*)(ll, ll)>(lcm)); }
ll pow(ll x, ll y, ll z) { ll a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
ll inv(ll x, ll m) { return pow(x, m - 2, m); }

template<typename T> bool chmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<typename T> bool chmin(T& x, const T& y) { return x > y ? x = y, true : false; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_cpp;

const ll INF = inf<ll>;
using P = pair<ll, ll>;
const ll M = 1000000007;
signed main() {
  ll k;
  cin >> k;
  char s[20];
  REP(i, 20) s[i] = '\0';
  auto f = [&](auto f, ll d, ll i) -> void {
    if (i==0){
      for (char a = '1'; a <= '9'; a++) {
        s[0] = a;
        f(f, d, i + 1);
      }
    }else if (d==i){
      k--;
      if(k==0){
        cout << s << endl;
        exit(0);
      }
    }else {
      for (
        char b = max('0', (char)(s[i-1]-1));
        b <= min('9', (char)(s[i-1]+1));
        b++) {
        s[i] = b;
        f(f, d, i + 1);
      }
    }
  };
  ll d = 1;
  while (d) {
    f(f, d, 0);
    d++;
  }
}


Measured memory_bytes: 256
/*input
100000 1
1 100000 100
*/
#include "bits/stdc++.h"
using namespace std;
long long x[100005],y[100005],z[100005],vis[100005],n;
vector<int> v[100005];
void dfs(int u){
	vis[u] = 1;
	for(auto i:v[u]) if(!vis[i]) dfs(i);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	long long q,m,k,h,ans=0,sum=0,p;
	cin>>n>>m;
	for(int i=1;i<=m;++i){
		cin>>x[i]>>y[i]>>z[i];
		v[x[i]].push_back(y[i]);
		v[y[i]].push_back(x[i]);
	}
	for(int i=1;i<=n;++i) if(!vis[i]){
		++ans;
		dfs(i);
	}
	cout<<ans;
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(auto i = (N) - 1; i >= 0; i -= 1)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it!= v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand mtrand
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cout << #v << " = "; array_out(v , ##__VA_ARGS__);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
#endif
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = 0x1FFFFFFFFFFFFFFFLL;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >> (istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}

random_device seed_gen; mt19937_64 mtrand(seed_gen());
#define MOD 1000000007

int main(){
  ini(n,h,w);
  out((n - h + 1) * (n -  w + 1) );
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=35,inf=0x3f3f3f3f;
int cnt[N],n,res;
inline int min(R int x,R int y){return x<y?x:y;}
inline int abs(R int x){return x<0?-x:x;}
void dfs(int pos,int s,int ret){
	if(ret<=res)return;
	if(pos==12){
		if(cnt[12]){
			fp(i,1,23)if(s>>i&1)cmin(ret,abs(12-i));
			cmin(ret,12);
		}
		cmax(res,ret);
		return;
	}
	if(!cnt[pos])return dfs(pos+1,s,ret),void();
	cmin(ret,pos);
	if(cnt[pos]==2){
		fp(i,1,23)if(s>>i&1)cmin(ret,abs(pos-i)),cmin(ret,abs(24-pos-i));
		cmin(ret,abs(pos-(24-pos)));
		dfs(pos+1,s|(1<<pos)|(1<<(24-pos)),ret);
		return;
	}
	R int tmp=ret;
	fp(i,1,23)if(s>>i&1)cmin(tmp,abs(pos-i));
	dfs(pos+1,s|(1<<pos),tmp);
	tmp=ret;
	fp(i,1,23)if(s>>i&1)cmin(tmp,abs(24-pos-i));
	dfs(pos+1,s|(1<<(24-pos)),tmp);
}
int main(){
	scanf("%d",&n);
	for(R int i=1,x;i<=n;++i)scanf("%d",&x),++cnt[x];
	if(cnt[0]||cnt[12]>1)return puts("0"),0;
	fp(i,1,11)if(cnt[i]>2)return puts("0"),0;
	dfs(1,0,inf);
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#define maxn 500009
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const long long INF=1e18;
long long tree[maxn];
int n,E,T;
long long a[maxn],dp[maxn];
long long f[maxn];
void pushup(int rt){
	tree[rt]=min(tree[rt<<1],tree[rt<<1|1]);
}
void build(int l,int r,int rt){
	tree[rt]=INF;
	if(l==r){
		return;
	}
	int m=(l+r)>>1;
	build(lson);
	build(rson);
}
void update(int L,int R,long long val,int l,int r,int rt){
	if(L<=l&&r<=R){
		tree[rt]=min(tree[rt],val);
		return;
	}
	int m=(l+r)>>1;
	if(L<=m)
		update(L,R,val,lson);
	if(R>m)
		update(L,R,val,rson);
	pushup(rt);
}
long long query(int L,int R,int l,int r,int rt){
	if(L<=l&&r<=R)
		return tree[rt];
	long long res1=INF,res2=INF;
	int m=(l+r)>>1;
	if(L<=m) res1=query(L,R,lson);
	if(R>m) res2=query(L,R,rson);
	return min(res1,res2);
}
int main(){
	cin>>n>>E>>T;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	build(1,n,1);
	dp[0]=0;
	update(1,1,dp[0]-a[0],1,n,1);
	dp[0]=0;
	f[0]=INF;
	for(int i=1;i<=n;i++){
		int L=1,R=i;
		while(L<R){
			int M=(L+R)>>1;
			if(2LL*(a[i]-a[M])<=T)
				R=M;
			else
				L=M+1;
		}
		long long res=query(R,i,1,n,1);
		dp[i]=res+a[i]+T;
		if(R>1){
			dp[i]=min(dp[i],f[R-1]+3*a[i]);
		}
		f[i]=min(f[i-1],dp[i-1]+a[i]-a[i-1]-3*a[i]);
		update(i+1,i+1,dp[i]-a[i],1,n,1);
	}
	cout<<dp[n]+E-a[n]<<endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 4736
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
string S[8];
int H, W;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> H >> W;
    
    rep(i, H) cin >> S[i];
    bool ok = true;
    rep(i, H - 1) {
        rep(j, W - 1) {
            if (S[i][j] == '#' && S[i + 1][j] == '#' && S[i][j + 1] == '#') ok = false;
            if (S[i + 1][j + 1] == '#' && S[i][j + 1] == '#' && S[i + 1][j] == '#') ok = false;
        }
    }
    if(ok) cout << "Possible" << endl;
    else cout << "Impossible" << endl;


    return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

bool is_included(uint a, uint b) { return (a | b) == a; }

int main() {
  uint N, K;
  vector<pair<uint, ull> > vec;

  scanf("%u%u", &N, &K);

  uint ones = 0;
  vec.push_back(make_pair(K, 0ULL));
  FOR(i, 32) {
    if ((K & (ones + 1)) != 0) {
      vec.push_back(make_pair((K - (ones + 1)) | ones, 0ULL));
    }
    ones = (ones << 1) + 1;
  }

  FOR(i, N) {
    uint A, B;
    scanf("%u%u", &A, &B);

    for (auto& p : vec) {
      if (is_included(p.first, A)) {
        p.second += (ull)B;
      }
    }
  }

  auto it = max_element(
      vec.begin(), vec.end(),
      [](pair<uint, ull> a, pair<uint, ull> b) { return a.second < b.second; });

  printf("%llu\n", it->second);
  
  return 0;
}


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

int main(){
    vector<int> a(4);
    for (int i = 0; i < 4; ++i) {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    if(a[0]!=1){
        cout<<"NO"<<endl;
        return 0;
    }
    if(a[1]!=4){
        cout<<"NO"<<endl;
        return 0;
    }
    if(a[2]!=7){
        cout<<"NO"<<endl;
        return 0;
    }
    if(a[3]!=9){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int mod=1e9+7;
int min(int a,int b){
    return (a<b)?a:b;
}
int max(int a,int b){
    return (a>b)?a:b;
}
int fp(int a,int b){
    if(b==0) return 1;
    int x=fp(a,b/2);
    x=(x*x)%mod;
    if(b&1) x=(x*a)%mod;
    return x;
}


signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 srand(time(0));
 int x,y,z,k;
 cin>>x>>y>>z>>k;
 int ct=0;
 while(y<=x){
    y*=2;
    ct++;
}
 while(z<=y){
    ct++;
    z*=2;
}
//cout<<ct<<endl;
if(ct<=k)
{
    cout<<"Yes";
}
else
{
 cout<<"No";
}
}

Measured memory_bytes: 3648
H,W=map(int,input().split())
lines=[]
for i in range(H):
    lines.append(input().strip())

chars=dict()
for line in lines:
    for c in line:
        if c not in chars:
            chars[c]=0
        chars[c]+=1

def judge(H,W,chars):
    #両方奇数
    if H%2+W%2==2:
        ones=1
        twos=H//2 + W//2
    #両方偶数
    elif H%2+W%2==0:
        ones=0
        twos=0
    elif H%2==1:
        ones=0
        twos=W//2
    else:
        ones=0
        twos=H//2
    for c in chars:
        chars[c]%=4
        if chars[c]==0:
            continue
        if chars[c]==2:
            twos-=1
        elif chars[c]==3:
            twos-=1
            ones-=1
        else:
            ones-=1
    if ones<0 or twos<0:
        return False
    return True

if judge(H,W,chars):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int P = A % B;
  int X = P;
  int co = 2;
  int tf;
  while(true) {
    if(X == C) {
      tf = 0;
      break;
    }
    X = A * co % B;
    if(X == P) {
      tf = 1;
      break;
    }
    co++;
  }
  if(tf == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3644
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()

    print(n + pow(n, 2) + pow(n, 3))
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 72688
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, n, M, K;

int main(){
    ll w,h,x,y;
    cin >> w >> h >> x >> y;
    long double d = 1.0*w*h/2;
    cout << setprecision(12) << d <<" ";
    if(2*x == w && 2*y == h) cout << 1;
    else cout << 0;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)



int main() {
    int a, b, x;
    
    cin >> a >> b >> x;
    
    cout << ((a <= x && x <= a + b)? "YES" : "NO") << endl;
}


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

int main(){
	long long int n;
	cin>>n;
	long long int u= n/11;
	long long int ans= 2LL*u;
	if (n%11>6) ans+=2;
	else if (n%11!=0) ans++;
	cout<<ans<<endl;
}



Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))

s = 0
maxL = 0

for i in range(N):
    if L[i] > maxL:
        maxL = L[i]
       
    
    s = s+L[i]


if s-maxL  > maxL:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>

int car(char a){
	if(a == 'a'){
		return 0;
	}else if(a == 'b'){
		return 1;
	}else{
		return 2;
	}
}

int main(){

	char S[3][101];
	int cnt[3] = {0,0,0};
	int k = 0;
	for(int i=0; i<3; i++){
		scanf("%s",S[i]);
	}

	while(1){
		if(cnt[k] == strlen(S[k])){
			if(k == 0){
				printf("A");
				return 0;
			}else if(k == 1){
				printf("B");
				return 0;
			}else{
				printf("C");
				return 0;
			}
		}
		cnt[k]++;
		k = car(S[k][cnt[k]-1]);

	}

}

Measured memory_bytes: 128
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
from itertools import permutations
def main():
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    r = [i-1 for i in r]
    l = [[0] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        l[a][b] = c
        l[b][a] = c
    G = csr_matrix(l)
    dd = dijkstra(G, directed=False)
    ans = 10**100
    for i in permutations(r, len(r)):
        t = 0
        for j in range(len(r)-1):
            t += dd[i[j]][i[j+1]]
        ans = min(ans, t)
    return int(ans)
print(main())


Measured memory_bytes: 16584
#include "bits/stdc++.h"
using namespace std;

class Cube{
public:
	int f[6];
	Cube(){}
		void roll_z(){roll(1,2,4,3);}
		void roll_y(){roll(0,2,5,3);}//to W
		void roll_x(){roll(0,1,5,4);}//to N
		void roll(int i,int j,int k, int l){
			int t=f[i];f[i]=f[j];f[j]=f[k];f[k]=f[l];f[l]=t;
		}
		void move(char ch){
			if(ch=='E')for (int i = 0; i < 3; ++i) {roll_y();}
			if(ch=='W')roll_y();
			if(ch=='N')roll_x();
			if(ch=='S')for (int i = 0; i < 3; ++i) {roll_x();}
		}
};
bool eq(Cube c1,Cube c2){
	for (int i = 0; i < 6; ++i) {
		if (c1.f[i] != c2.f[i]) {return false;}
	}return true;
}

bool equal(Cube c1,Cube c2){
	for (int i = 0; i < 6; ++i) {
		for (int j = 0; j < 4; ++j) {
			if (eq(c1,c2)) return true;
						c1.roll_z();
		}
		if (i%2==0) {c1.roll_y();}
		else{c1.roll_x();}
	}
	return false;
}


int main() {
	int n;
	cin>>n;
	Cube c[n];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 6; ++j){
			cin>>c[i].f[j];
		}
	}
	for (int i = 0; i < n-1; ++i) {
		for (int j = i+1; j < n; ++j) {
			if (equal(c[i],c[j])){cout<<"No"<<endl;return 0;}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}



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

int main(){
    int a,b,n=0,k=0,c;cin>>a>>b;c=b;
    while(b!=0){
        b/=10;
        n++;
    }
    int x=c+a*pow(10,n);
    for(int i=4;i<350;i++){
        if(pow(i,2)==x) {
            k++;
            break;
        }
    }
    if(k==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t;cin>>t;while(t--)
#define f(i,n) for (int i=0;i<n;i++)
#define fa(i,a,b) for (int i=a;i<b;i++)
#define b(i,a,b) for (int i=a;i>=b;i--)
#define pb push_back
#define pp pop_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define fi first    
#define se second
#define SZ(x) ((int)(x).size())
#define db(x) cout<<">"<<#x<<" = "<<x<<endl;
#define MOD 1000000007
#define vll vector<ll>
#define ce cout<<endl
int main() 
{ 
    fast;
    int n,k,i,ans=0;
    cin>>n>>k;
    int a[n];
    f(i,n)
        cin>>a[i];
    sort(a,a+n);
    f(i,k)
        ans+=a[i];
    cout<<ans<<endl;
    return 0; 
} 

Measured memory_bytes: 3636
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;


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

    if (N <= 999) {
        cout << "ABC" << endl;
    }
    else {
        cout << "ABD" << endl;
    }
}

Measured memory_bytes: 3572
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <cstring>
#include <functional>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
inline int in(){ int x; scanf("%d",&x); return x;}

int main(){
    int i,j,k;

    while(1){
        int res[3];
        int a = in();
        int b = in();
        if(a == 0 && b == 0) break;

        int fe = b-a;
        rep(i,3) res[i] = 0;
        while(1000 <= fe){ fe -= 1000; res[2]++;}
        while(500 <= fe){ fe -= 500; res[1]++;}
        while(100 <= fe){ fe -= 100; res[0]++;}

        rep(i,3) printf("%d%c",res[i],(i==2)?'\n':' ');
    }

  return 0;
}

Measured memory_bytes: 0
n = int(input())
X = []
Y = []

for i in range(n):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)

import math
import itertools
ans = 0
for p in list(itertools.permutations(range(n))):
    for i in range(len(p)):
        if i == len(p)-1:
            continue
        ans += math.sqrt((X[p[i]]-X[p[i+1]])**2+(Y[p[i]]-Y[p[i+1]])**2)
ans /= math.factorial(n)
print(ans)

Measured memory_bytes: 45556
N, M = map(int,input().split())
S = [0] * M
k = [0] * M
for i in range(M):
    KS = list(map(int,input().split()))
    k[i] = KS[0]
    S[i] = KS[1:] #1から最後までの書き方
P = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    global_count = 0
    for j in range(M):
        local_count = 0
        for x in S[j]:
            if (i >> (x-1)) % 2 == 0:
                continue
            else:
                local_count += 1
        if local_count % 2 == P[j]:
            global_count += 1
    if global_count == M:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
int main(void){
   double x,h,s,work1,work2;
   while(scanf("%lf%lf",&x,&h)){
      if(x==0 && h==0)break;
      work1=h*h+x*x/4;
      work2=sqrt(work1);
      printf("%f\n",2*work2*x+x*x);
   }
   return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int K,X;
    cin >> K >> X;
    int ansl = X - K + 1;
    int ansr = X + K - 1;

    for(int i = ansl;i <= ansr;i++){
        cout << i << endl;
    }

    return 0;
}


Measured memory_bytes: 256