akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define pb push_back
#define mod 1000000007
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dx8[]={1,-1,0,0,1,1,-1,-1};
int dy8[]={0,0,1,-1,1,-1,1,-1};

ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}
// ll n,m;
// ll c;

// vector<ll> v[200001];
// ll vis[200001];
// void dfs(ll node){
// 	vis[node]=1;
// 	c++;

// 	for(auto i:v[node]){
// 		if(vis[i]==0){
			

// 			dfs(i);

// 		}
// 	}
// }
ll sumi(ll a[], ll n) 
{ 
    
    map<ll, ll> cnt; 
  
    // Traverse in the list from start to end 
    // number of times a[i] can be in a pair and 
    // to get the difference we subtract pre_sum. 
    ll ans = 0, pre_sum = 0; 
    for (ll i = 0; i < n; i++) { 
        ans += (i * a[i]) - pre_sum; 
        pre_sum += a[i]; 
  
        // if the (a[i]-1) is present then 
        // subtract that value as f(a[i], a[i]-1)=0 
        if (cnt[a[i] - 1]) 
            ans -= cnt[a[i] - 1]; 
  
        if (cnt[a[i] + 1]) 
            ans += cnt[a[i] + 1]; 
  
        // keeping a counter for every element 
        cnt[a[i]]++; 
    } 
    return ans; 
} 
void  findProductSum(ll  a[], ll  n) 
{ 
     
        int sum = 0 ;
        
        int dp[n];
        for(int i=n-1;i>=0;i--)
        {
            dp[i] = sum;
            sum=(sum%mod+a[i]%mod)%mod;
        }
        
        sum = 0 ;
        
        for(int i=0;i<n;i++)
        {
            sum =(sum%mod+ a[i]%mod*dp[i]%mod)%mod;
        }
        
        cout<<sum<<endl;
} 

void solve(){
	
	ll   n;
	cin>>n;
	ll  a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];

	}
	findProductSum(a,  n); 
	










return;
}




int main()
{  
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
    fast;
    ll t;
    t=1;
   //cin>>t;
    while(t--){
    	solve();
    }
    
   
  



#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}

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

using namespace std;

int main(void) {
	int i = 0, num, sum = 0, ans = 1 << 30;
	cin >> num;
	vector<int> d(num), a(num), b(num);
	for (; i < num; i++) {
		scanf("%d", &d[i]);
		sum += d[i];
		a[i] = sum;
	}
	for (sum = 0, i = num - 1; i >= 0; i--) {
		b[i] = sum;
		sum += d[i];
	}
	for (i = 0; i < num; i++)
		ans = min(ans, abs(a[i] - b[i]));
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[100005];
bool b[100005];
int main(){
	int n,m,x,y;
	int i,j,k;
	int s=0;
	for(i=0;i<100005;i++){ a[i]=1;}
	b[0]=true;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>x>>y;
		x--; y--;
		if(b[x])b[y]=true;
		a[y]++;
		if(a[x]==1)b[x]=false;
		a[x]--;
	}
	for(i=0;i<n;i++){
		if(b[i])s++;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>

#define MAX_N (100)
#define MAX_C (100)
#define ABS(x) ((x) >= 0 ? (x) : -(x))

int main(int argc, char *argv[]) {
  long N, x[MAX_N], y[MAX_N], h[MAX_N];
  scanf("%ld", &N);
  for (int i = 0; i < N; i++)
    scanf("%ld %ld %ld", &x[i], &y[i], &h[i]);

  for (int i = 0; i <= MAX_C; i++) {
    for (int j = 0; j <= MAX_C; j++) {
      long possible = 1, H;
      for (int k = 0; k < N; k++) {  // Set initial H
        long h_k = h[k], manhattan_distance = ABS(x[k] - i) + ABS(y[k] - j);
        if (h_k > 0) {
            H = h_k + manhattan_distance;
            break;
        }
      }
      for (int k = 0; k < N; k++) {
        long h_k = h[k], manhattan_distance = ABS(x[k] - i) + ABS(y[k] - j);
        if (h_k > 0 && h_k + manhattan_distance == H) {
          continue;
        } else if (h_k == 0 && manhattan_distance >= H) {
          continue;
        } else {
          possible = 0;
          break;
        }
      }
      if (possible) {
        printf("%d %d %ld\n", i, j, H);
        return 0;
      }
    }
  }
  while (1)
    ;
  
  return 0;
}


Measured memory_bytes: 128
import copy
N = int(input())
p = list(map(int, input().split()))
pcopy = copy.deepcopy(p)
ans = sorted(p)

is_ascend = False
if p == ans:
    is_ascend = True

for i in range(N):
    for j in range(i+1,N):
        p = copy.copy(pcopy)
        p[i], p[j] = p[j], p[i]
        if p == ans:
            is_ascend = True

if is_ascend:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
#define w(x) int x;cin>>x;while(x--)
#define ll long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define vi vector<int>
#define ff first
#define ss second
#define fr(a,b) for(int i=a;i<=b;i++)
#define inf 1e18
#define mod 998244353
int main()
{
    string s,t;
    cin>>s>>t;
    int n=s.length();
    int m=t.length();
    int ans=INT_MAX;
    int c=0;
    for(int i=0;i<=n-m;i++)
    {
        c=0;
        for(int j=i;j<i+m;j++)
        {
            if(s[j]!=t[j-i])
            c++;
        }
        ans=min(c,ans);
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3632
using System;
class Program
{
    static void Main(string[] args)
    {
        int a = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();

        if (a >= 3200)
        {
            Console.WriteLine(s);
        }
        else
        {
            Console.WriteLine("red");
        }
    }
}

Measured memory_bytes: 11092
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
    set<int> s;
    int q; cin >> q;
    while (q--) {
        int com, x; cin >> com >> x;
        if (com == 0) {
            s.emplace(x);
            cout << s.size() << endl;
        } else if (com == 1) {
            cout << s.count(x) << endl;
        } else if (com == 2) {
            s.erase(x);
        }
    }
    return 0;
}


Measured memory_bytes: 12388
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int N,x=0,ans=0;
  string S;
  cin>>N>>S;
  for(int i=0; i<N; ++i){
    if(S.at(i)=='I') x++;
    else x--;
    ans=max(ans,x);
  }
  cout<<ans<<endl;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

#define MAX_V 1000
  const ll INF = (ll)(1e15);
// Dinic http://www.prefield.com/algorithm/graph/dinic.html
struct dinic{
  struct edge{int to;ll cost;};
  int n;
  vector< vector<edge> > G;
  vector<vl> flow, capacity;
#define RESIDUE(s,t) (capacity[s][t]-flow[s][t])
  vi level;
  vector<bool> finished;
  dinic(int _n){
    n = _n;
    G.assign(n,vector<edge>());
    flow.assign(n,vl(n,0));
    capacity.assign(n,vl(n,0));
    level.assign(n,0);
    finished.assign(n,false);
  }
  void add_edge(int from,int to,ll cost){
    assert(0<=from && from<n);
    assert(0<=to && to<n);
    G[from].push_back((edge){to,cost});
    G[to].push_back((edge){from,0ll});  // 逆に流すフローのためのダミー辺
  }
  ll dfs(int u, int t, ll cur){
    if(u==t || cur==0) return cur;
    if(finished[u]) return 0;
    finished[u] = true;
    REP(i,G[u].size()){
      edge e = G[u][i];
      if(level[e.to] > level[u]){
        ll f = dfs(e.to, t, min(cur, RESIDUE(u,e.to)));
        if(f>0){
          flow[u][e.to] += f;
          flow[e.to][u] -= f;
          finished[u] = false;
          return f;
        }
      }
    }
    return 0;
  }
  ll calc(int s, int t){
    REP(i,n)REP(j,n)flow[i][j]=capacity[i][j]=0;
    REP(u,n)REP(j,G[u].size()){
      edge e = G[u][j];
      capacity[u][e.to] += e.cost;
    }
    ll total = 0;
    while(true){
      REP(i,n)level[i] = -1;
      level[s] = 0;
      queue<int> Q; Q.push(s);
      int d = n;
      while(!Q.empty()){
        int u = Q.front(); Q.pop();
        REP(i,G[u].size()){
          edge e = G[u][i];
          if(RESIDUE(u,e.to) > 0 && level[e.to] == -1){
            Q.push(e.to);
            level[e.to] = level[u] + 1;
          }
        }
      }
      REP(i,n)finished[i]=false;
      bool flag = false;
      while(true){
        ll f = dfs(s,t,INF);
        if(f==0)break;
        total += f;
        flag = true;
      }
      if(!flag)break;
    }
    return total;
  }
};

int n;
ll a[125];



int main(){
  cin>>n;
  REP(i,n)cin>>a[i];
  // n = 100;
  // REP(i,n)a[i] = rand() - rand();

  dinic D(n+2);
  ll M = (ll)(1e9);
  ll Z = 2ll*M;
  int s = n, t = n+1;
  REP(i,n){
    D.add_edge(s,i,Z-M);
    D.add_edge(i,t,Z-(a[i]+M));
    REP(j,i){
      if((i+1)%(j+1)==0){
        D.add_edge(i,j,INF);
      }
    }
  }

  ll flow = D.calc(s,t);
  ll ans = Z*n - flow - M*n;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
import java.util.*;

class Main{
  public static void main (String[] args){
    Scanner sc = new Scanner (System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();
    System.out.println((H-h)*(W-w));
  }
}

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


int main(){
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> C(A);
  vector<int> D(B);
  int min_c = INT_MAX;
  for(auto& c : C){
    cin >> c;
    min_c = min(c, min_c);
  }  
  int min_d = INT_MAX;
  for(auto& d : D){
    cin >> d;
    min_d = min(d, min_d);
  }

  int ans = min_c + min_d;
  for(int ii=0; ii<M; ii++){
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    ans = min(ans, C[x]+D[y]-c);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int n=0;
  cin >> n;
  n=n%10;
  if(n==3)	cout<<"bon";
  else if(n==0||n==1||n==6||n==8)	cout<<"pon";
  else	cout<<"hon";
}

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
 
class Main
{
	public static void main(String[] args)
	{
        	List<Integer> num1 = new ArrayList<Integer>();
		List<Integer> num2 = new ArrayList<Integer>();
		Scanner scanner = new Scanner(System.in);
        	int x = 1;
		int y = 1;
 		while(!(x == 0) || !(y == 0))
		{
			x = scanner.nextInt();
			y = scanner.nextInt();
			if(x == 0 && y == 0)
			{
				break;
			}
			if(x <= y)
			{ 
				num1.add(x);
				num2.add(y);
			}
			if(x > y)
			{
				num1.add(y);
				num2.add(x);
			}
		}
		for(int i=0; i<num1.size(); ++i)
		{
			System.out.println(num1.get(i) + " " + num2.get(i));
		}
    	}
}


Measured memory_bytes: 37352
#include <iostream>
#include <set>
#include <iomanip>
int main()
{
    double a;
    std::cin >> a;
    const double pi = 3.14159265358979323846;

    std::cout << std::fixed << std::setprecision(6);
    std::cout << a * a * pi << " " << a * 2 * pi << "\n";

    return 0;
}


Measured memory_bytes: 3276
# coding: utf-8

n,k = map(int,input().split())

if n==k:
    print(0)
    
############################
if n < k:
    for _ in range(2):
        abs_val = abs(n-k)
        
        if abs_val<=n:
            n=abs_val
            
    print(n)

############################
if n > k:
    z = n//k
    n = n - k*z
    
    for _ in range(4):
        abs_val = abs(n-k)
        
        if abs_val<=n:
            n=abs_val
            
    print(n)

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<cstdio>
#define maxn 110
using namespace std;
int last[maxn],_left[maxn],tot,n,m,e,ans;
bool vis[maxn],used[maxn];
struct node{
	int x,y;
}a[maxn],b[maxn];
void getnode(node& tmp){
	scanf("%d%d",&tmp.x,&tmp.y);
}
bool operator <(node a,node b){
	return a.x<b.x&&a.y<b.y;
}
struct edge{
    int v,next;
}edges[maxn*maxn];
void add_edge(int u,int v){
    edges[tot].v=v,edges[tot].next=last[u],last[u]=tot++;
    return;
}
bool match(int u){
    for(int i=last[u];~i;i=edges[i].next){
        int v=edges[i].v;
        if(!vis[v]){
            vis[v]=1;
            if(!_left[v]||match(_left[v])){
                _left[v]=u;
                return 1;
            }
        }
    }
    return 0;
}
void init(){
    ans=tot=0;
    memset(_left,0,sizeof(_left));
    memset(vis,0,sizeof(vis));
    memset(last,-1,sizeof(last));
    memset(used,0,sizeof(used));
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    getnode(a[i]);
    for(int i=1;i<=n;++i)
    getnode(b[i]);
    for(int i=1;i<=n;++i)
    for(int j=1;j<=n;++j)
    if(a[i]<b[j]){
	    add_edge(i,j);
	    if(!_left[j]&&!used[i])
		_left[j]=i,used[i]=1,++ans;
    }
}
void solve(){
    for(int i=1;i<=n;++i)
    if(!used[i]&&match(i)){
        memset(vis,0,sizeof(vis));
        ++ans;
    }
    printf("%d\n",ans);
    return;
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

    int main(){
      int n;
      cin >> n;
      int l[n];
      rep(i,n)cin >> l[i];
      sort(l,l+n);
      int sum=0;
      rep(i,n-1)sum+=l[i];
      if(sum>l[n-1])cout << "Yes" << endl;
      else cout << "No" << endl;
      return 0;}

Measured memory_bytes: 256
n,m=map(int,input().split())
res=[0 for i in range(m+1)]
for i in range(n):
    ka=list(map(int,input().split()))
    for j in range(ka[0]):
        res[ka[j+1]]+=1
ans=0
for i in range(m):
    if res[i+1]==n:
        ans+=1
print(ans)
        
    
    

    


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

#define coutv(v) for (int i = 0; i < (v).size(); ++i) cout << v[i] << ' '; cout << endl;
#define coutvv(v) for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cout << v[i][j] << ' '; cout << endl;}
#define debugv(v) {for (int i = 0; i < (v).size(); ++i) cerr << v[i] << ' '; cerr << endl;}
#define debugvv(v) {for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cerr << v[i][j] << ' '; cerr << endl;}}
#define TC int TESTCASE; cin >> TESTCASE; while (TESTCASE--)
typedef long long ll;




int main() {
    int n;
    cin >> n;
    int d; cin >> d;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        long double x,y; cin >> x >> y;
        if (sqrt(x*x + y*y) <= d) {
            cnt += 1;
        }
    }
    cout << cnt;
}


Measured memory_bytes: 3736
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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


int a[6];

int main() {

	cin >> a[1] >> a[2] >> a[3] >> a[4] >> a[5];

	rrep(i, 5) {
		if (i != a[i]) {
			cout << i << endl;
			break;
		}
	}



	return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
    const int MAX =200002;
const int MOD =1000000007;
   int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
     signed main(){
 int n;
 cin>>n;
 int a[n],maxa=0;
 for(int i=0;i<n;i++){cin>>a[i];maxa=max(maxa,a[i]);}
 int ans1=a[0],ans2=1;
 for(int i=1;i<n;i++){
    
    int p=ans1,q=a[i];
     if(p>q)swap(p,q);
     while(p!=0){
         q%=p;
         swap(p,q);
     }
     ans1=q;
 }
bool used[1000001]={},ux[1000001]={};
for(int i=0;i<n;i++)ux[a[i]]=true;
for(int i=2;i<1000001;i++){
    if(used[i])continue;
    int k=0;
    for(int j=1;j*i<1000001;j++){
        if(ux[i*j])k++;
        used[i*j]=true;
    }
    if(k>1){
        ans2=i;
        break;
    }
}
 if(ans1==1){
     if(ans2==1)cout<<"pairwise coprime"<<endl;
     else cout<<"setwise coprime"<<endl; 
 }else cout<<"not coprime"<<endl;
   }
     


 


 






    





      

        


Measured memory_bytes: 13324
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 

typedef unsigned long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pll> vll;
typedef vector <pii> vii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/*********** TEMPLATE ENDS HERE *************/

main()
{
	int a, b;
	cin >> a >> b;
	
	if(a % 500 <= b)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
import sys
from heapq import heappush,heappop
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    d={}
    for i in range(N):
        A,B=map(int,input().split())
        if A in d:
            d[A].append(B)
        else:
            d[A]=[B]
    h=[]
    ans=0
    for i in range(1,M+1):
        if i in d:
            l=d[i]
            for x in l:
                heappush(h,-x)
        if h:
            ans-=heappop(h)
    print(ans)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 71388
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b; cin >> a >> b;
    cout << abs(6-a-b) << "\n";
}



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

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

signed main()
{
    int n; cin >> n;
    vector<string> s(n);

    rep(i, n) {
        cin >> s[i];
    }

    string t; cin >> t;
    int acnt = 0, bcnt = 0, ccnt = 0;

    rep(i, n) {
        bool f = false;

        rep(j, s[i].size()) {
            if (s[i][j]=='?') break;
            if (j >= (int)t.size()) break;
            if (s[i][j] < t[j]) {
                f = true;
                acnt += 1;
                break;
            }
            if (s[i][j] > t[j]) {
                f = true;
                bcnt += 1;
                break;
            }
        }

        if (f) continue;

        int aa = 0;

        {
            string tmp = s[i];
            rep(i, tmp.size()) if (tmp[i] == '?') tmp[i] = 'a';
            if (tmp > t) bcnt += 1;
        }

        {
            string tmp = s[i];
            rep(i, tmp.size()) if (tmp[i] == '?') tmp[i] = 'z';
            if (tmp < t) acnt += 1;
        }
    }

    ccnt = n - acnt - bcnt;

    vi ans;

    for (int i = 1; i <= n + 1; ++i) {
        if (acnt < i && acnt + ccnt >= i - 1 && n + 1 - bcnt >= i ) {
            ans.PB(i);
        } 
    }

    rep(i, ans.size()) {
        printf("%d%c",ans[i],i==(int)ans.size()-1?'\n':' ');
    }
}


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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  string s;cin>>s;
  if(s=="SUN")fin(7);
  if(s=="MON")fin(6);
  if(s=="TUE")fin(5);
  if(s=="WED")fin(4);
  if(s=="FRI")fin(2);
  if(s=="THU")fin(3);
  if(s=="SAT")fin(1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int n; cin >> n;
    rep(i,n){
        ll a; cin >> a;
        if(a%2==1){
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int x[] = new int[n];
		int y[] = new int[n];
		int h[] = new int[n];
		
		int bx=0, by=0, bh=0;
		
		for(int i=0;i<n;i++){
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			h[i] = sc.nextInt();
			if(h[i]>0){
				bx = x[i];
				by = y[i];
				bh = h[i];
			}
		}
		
		for(int cx = 0;cx<=100;cx++){
			for(int cy=0;cy<=100;cy++){
				int H = bh + Math.abs(cx-bx) + Math.abs(cy-by);
				
				boolean f = true;
				for(int k=0;k<n;k++){
					if(Math.max(0, H-Math.abs(cx - x[k]) - Math.abs(cy - y[k])) != h[k]){
						f = false;
						break;
					}
				}
				
				if(f){
					System.out.println(cx+" "+cy+" "+H);
					return;
				}
			}
		}
		
	}

}


Measured memory_bytes: 21844
x = list(map(int, input().split()))
a,b,c =0,0,0
for i in x:
    if i in [1,3,5,7,8,10,12]:
        a += 1
    elif i in [4,6,9,11]:
        b += 1
    else:
        c += 1
if (a<2) and (b<2) and (c<2):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include <stdio.h>
#define INF (1<<21)
#define W 0
#define G 1
#define B 2

int n,A[100][100];

int main(){
  int e,i,j;
  scanf("%d",&n);

  for(i =0;i<n;i++){
     for(j =0;j<n;j++){
       scanf("%d",&e);
       A[i][j] = (e == -1) ? INF : e;
     }
  }

  printf("%d\n",prim());

  return 0;
}


int prim(){
  int i,u,v,min,sum =0;
  int d[100],p[100],color[100];

  for(i =0;i<n;i++){
    d[i] = INF;
    p[i] = -1;
    color[i] = W;
  }

  d[0] = 0;

  while(1){
    min = INF;
    u = -1;
    for(i =0;i<n;i++){
      if(min > d[i] && color[i] != B){
	u = i;
	min = d[i];
      }
    }
    if(u == -1)break;
    color[u] = B;
    for(v = 0;v < n;v++){
      if(color[v] != B && A[u][v] != INF){
	if(d[v] > A[u][v]){
	  d[v] = A[u][v];
	  p[v] = u;
	  color[v] = G;
	}
      }
    }
  }
    
  for(i =0;i<n;i++){
    if(p[i] != -1){
      sum += A[i][p[i]];
    }
  }
  return sum;
}


      
    
      



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

const ll p = 1e9+7;

int n, m;
ll dp[305][305];
ll dp1[305][305];

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

	dp[1][0] = 1;
	for (int i = 1; i <= m; ++i) {
		memset(dp1, 0, sizeof(dp1));
		for (int j = 1; j <= i; ++j)
			for (int k = 0; k <= i-j; ++k) {
				if (k == 0) {
					dp1[j][k] = (dp1[j][k] + j*dp[j][k])%p;
					dp1[j][k+1] = (dp1[j][k+1] + (n-j)*dp[j][k])%p;
				} else {
					dp1[j][k] = (dp1[j][k] + k*dp[j][k])%p;
					dp1[j+k][0] = (dp1[j+k][0] + j*dp[j][k])%p;
					dp1[j][k+1] = (dp1[j][k+1] + (n-j-k)*dp[j][k])%p;
				}
			}
		memcpy(dp, dp1, sizeof(dp));
	}

	cout << dp[n][0] << endl;
}

Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();

		if(Character.isUpperCase(s[0])){
			System.out.println("A");
		} else {
			System.out.println("a");
		}
	}
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

static const llint MAX = 2e5 + 5;
// static const int NIL = -1;
// static const llint INF = 1<<21;
static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

void init_combination() {
    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;
    }
}

llint combination(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;
}

int main(void) {
    llint n, k;
    cin >> n >> k;
    if(n<k) k = n;
    init_combination();

    llint ans = 0, anstmp;
    for(llint ik=0;ik<=k;ik++) {
        anstmp = combination(n, ik);
        anstmp *= combination(n-1,n-ik-1);
        anstmp %= MOD;
        ans += anstmp;
        ans %= MOD;
    }

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


Measured memory_bytes: 8328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    int t[n],x[n],y[n];
    for(int i = 0; i < n; i++){
        cin >> t[i] >> x[i] >> y[i];
    }
    bool a = true, b = true;
    for(int i = 0; i < n; i++){
        if(t[i] < x[i] + y[i]){
            a = false;
        }
        if(t[i] % 2 != (x[i] + y[i]) % 2){
            b = false;
        }
    }
    if(a && b) cout << "Yes";
    else cout << "No";

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define be(v) (v).begin(), (v).end()

int main() {
	int n; cin >> n;
	vint a(n);
	vint b(n);
	rep(i,n) {
		cin >> a[i];
		b[i]=a[i];
	}
	sort(be(b));
	reverse(be(b));
	int max1=b[0];
	int max2=b[1];
	rep(i,n) {
		if(a[i]==max1) cout << max2 << endl;
		else cout << max1 << endl;
	}
}

Measured memory_bytes: 4828
#include <cstdio>
#include <algorithm>
#include <stdint.h>

int main(){
  int64_t I,O,T,J,L,S,Z;
  scanf("%ld %ld %ld %ld %ld %ld %ld",&I,&O,&T,&J,&L,&S,&Z);
  int64_t best=(I/2+L/2+J/2)*2;
  if(I&&L&&J){
    best=std::max(best,3+((I-1)/2+(L-1)/2+(J-1)/2)*2);
  }
  printf("%ld\n",best+O);
  return 0;
}


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

int main() {
    string S;
    cin >> S;
    int N = S.size();
    long long res = 0;
    for (int bit = 0; bit < (1<<(N-1)); ++bit) {
        long long tmp = 0;
        for (int i = 0; i < N-1; ++i) {
            tmp *= 10;
            tmp += S[i] - '0';
            if (bit & (1<<i)) res += tmp, tmp = 0;
        }
        tmp *= 10;
        tmp += S[N-1] - '0';
        res += tmp;
    }
    cout << res << endl;
}

Measured memory_bytes: 3632
#include<map>
#include<cmath>
#include<stack>
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int x,y;
int main(){
	scanf("%d%d",&x,&y);
	if(x%y==0)puts("-1");
	else printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
M = 10**9 + 7

E = "ACGT"

from collections import defaultdict

ngp = [
    "AGC?", "GAC?", "ACG?",
    "?AGC", "?GAC", "?ACG",
    "A?GC", "AG?C"
]

ng = set(["AGC", "GAC", "ACG"])

for x in ngp:
    for c in E:
        ng.add(x.replace("?", c))

rs = {"": 1}

for i in range(N):
    nrs = defaultdict(int)
    for k, v in rs.items():
        for e in E:
            nk = (k + e)[-4:]
            if not nk in ng:
                nrs[nk[-3:]] += v
    rs = nrs

result = sum(nrs.values()) % M

print(result)

Measured memory_bytes: 3436
#include<bits/stdc++.h>
#define PI 2*acos(0)
#define ll long long
#define pii pair<int,int>
#define mx 100005
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    int p[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    sort(p,p+n);
    int sum=0,cnt=0;
    for(int i=0;i<n;i++){
        sum+=p[i];
        cnt++;
        if(cnt==k) break;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>

using namespace std;


int getSumOfDigits(int n){
  int sum = 0;
  while (n > 0){
    sum += (n%10);
    n /= 10;
  }
  return sum;
}

int main(){

  int n, a, b, sum=0;
  cin >> n >> a >> b;
  int sod;
  for (int d = 1; d <= n; d++){
    sod = getSumOfDigits(d);
    if ((a <= sod) & (sod <= b)){
      sum += d;
    }
  }
  cout << sum << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


const int INF = 1e9 + 5;

int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    const int K = 2;

    int N;
    cin >> N;
    vector<int> H(N);

    for (int &h : H)
        cin >> h;

    vector<int> dp(N, INF);
    dp[0] = 0;

    for (int i = 1; i < N; i++)
        for (int j = max(i - K, 0); j < i; j++)
            dp[i] = min(dp[i], dp[j] + abs(H[i] - H[j]));

    cout << dp.back() << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
bool poss[5000];
signed main(){
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	poss[0] = true;
	for(int i=1;i<=f;i++){
		if( i - c >= 0 && poss[i-c] == true )poss[i]=true;
		if( i - d >= 0 && poss[i-d] == true )poss[i]=true;
	}
	int answ=-1,anss=-1;
	double cur = -0.1;
	for(int i=0;i<=f/(100*a);i++){
		int nk = f - 100 * a * i;
		int mz = 100 * a * i;
		for(int j=0;j<=nk/(100*b);j++){
			nk -= 100 * b * j;
			mz += 100 * b * j;
			int mxs = min( mz/100 * e, nk);
			while( poss[mxs] == false )mxs--;
			double dens = 1.0 * mxs / ( mz + mxs );
			if( dens > cur ){
				cur = dens;
				answ = mz + mxs;
				anss = mxs;
			}
		}
	}
	cout<<answ<<" "<<anss<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

tuple<ll, ll, ll> mul[8]=
                {mt(1,1,1),
			     mt(1,1,-1),
			     mt(1,-1,1),
			     mt(1,-1,-1),
			     mt(-1,1,1),
			     mt(-1,1,-1),
			     mt(-1,-1,1),
			     mt(-1,-1,-1)};
int main(){
  int n, m;
  cin >> n >> m;
  ll x[n],y[n],z[n];
  rep(i,n){
    cin >> x[i] >> y[i] >> z[i];
  }
  ll ans=0;
  rep(k,8){
    ll t[n];
    rep(i,n) {
      t[i]=x[i]*get<0>(mul[k]);
      t[i]+=y[i]*get<1>(mul[k]);
      t[i]+=z[i]*get<2>(mul[k]);   
    }
    sort(t,t+n);
    ll ta=0;
    for(int i=n-1; i>=n-m;i--) ta+=t[i];
    ans =max(ans,ta);
  }
  cout << ans << endl;
  

  
  return 0;

}


Measured memory_bytes: 256
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
 
ll mpow(ll a, ll b){
	if(b >= (MOD-1)) b %= (MOD-1);
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}
 
ll mpow(ll a, ll b, ll p){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2,p);
	t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}
 
ll modinverse(ll a, ll m){
	ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) return 0; 
    while (a > 1){
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }
    if (x < 0) x += m0; 
    return x; 
}
 
ll range(ll l, ll r){
	return l + rand()%(r-l+1);
}

void solve(){
	ll n;
	cin >> n;
	ll dist[n][n];
	forn(i,n){
		forn(j,n){
			char c;
			cin >> c;
			if(i==j) dist[i][j] = 0;
			else if(c=='1') dist[i][j] = 1;
			else dist[i][j] = INF;
		}
	}
	forn(i,n){
		forn(j,n){
			forn(k,n){
				dist[j][k] = min(dist[j][k],dist[i][j]+dist[i][k]);
			}
		}
	}
	ll a1,a2,mm = 0;
	forn(i,n){
		forn(j,n){
			if(dist[i][j]>mm){
				mm = dist[i][j];
				a1=i,a2=j;
			}
		}
	}
	forn(i,n){
		forn(j,n){
			if(dist[i][j]==1 && (dist[a1][i]+dist[a1][j])%2==0){
				cout << -1 << ln;
				return;
			}
		}
	}
	cout << mm+1 << ln;
}
 
int main()
{
	fast_cin();
    ll t=1;
    // cin>>t;
    forn(i,t) {
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    }
    return 0;
}

Measured memory_bytes: 640
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

n = int(input()) 
a = list(map(int,input().split()))

l = lcm(*a)

MOD = 10**9+7
ans = 0
for i in range(n):
    ans += l // a[i]
print(ans % MOD)


Measured memory_bytes: 10416
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
/*
多倍長整数, cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
constexpr long double eps = 1e-9;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int k;
	scanf("%d", &k);
	string s;
	scans(s);
	if (s.length() <= k)prints(s);
	else {
		prints((s.substr(0, k) + "..."));
	}

	Please AC;
}

Measured memory_bytes: 3788
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
#include<numeric>
#include<set>
#include<iterator>
#include<cstdio>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)
int INF=1e9;
const long long mod=1e9+7;
#define ll long long
 
int main(){
  int n,sum=0; cin>>n;
  rep(i,n+1){
    sum+=i;
  }
  cout<<sum<<endl;
  return 0;
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

ll MAX_V = 1100;
vector<vector<ll>> G(MAX_V);//隣接リスト(添え字は始点、値は終点)
vector<ll>x(MAX_V);
bool judgement=true;
P dfs(ll k){
  ll sumbuf=0;
  if(G[k].size()==0)return MP(x[k],0);
  vector<P>v;
  for(ll i=0;i<G[k].size();i++){
    auto tmp=dfs(G[k][i]);
    sumbuf+=tmp.fi+tmp.se;
    v.PB(tmp);
  }
  auto dp=vec((ll)v.size()+1,5001,false);
  dp[0][0]=true;
  rep(i,0,v.size()){
    rep(j,0,5001){
      if(dp[i][j]&&j+v[i].fi<=5000)dp[i+1][j+v[i].fi]=true;
      if(dp[i][j]&&j+v[i].se<=5000)dp[i+1][j+v[i].se]=true;
    }
  }
  ll maxbuf=-1;
  rep(i,0,x[k]+1)if(dp[v.size()][i])maxbuf=i;
  if(maxbuf==-1){
    judgement=false;
    return MP(0,0);
  }
  else return MP(x[k],sumbuf-maxbuf);
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  for(ll i=0;i<n-1;i++){
    ll p;cin>>p;
    G[p-1].PB(i+1);
  }
  rep(i,0,n)cin>>x[i];
  dfs(0);
  ans(judgement,"POSSIBLE","IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 1024
from functools import reduce
from operator import mul
from itertools import combinations
n = int(input())
cnt = [0]*5
for _ in range(n):
    s = input()
    if s[0] not in 'MARCH':
        continue
    i = 'MARCH'.index(s[0])
    cnt[i] += 1


ans = 0
for subset in combinations(range(5), 3):
    ans += reduce(mul, [cnt[i] for i in subset])

print(ans)


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

int main(){
    string s;
    cin >> s;
    int ans = 753;
    for(int i = 0; i < s.size() - 2; i++)
    {
        int num = abs(stoi(s.substr(i, 3)) - 753);
        if (num < ans) {
            ans = num;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, m, k, a;
bool like[31][31];
 
int main(){
	cin >> n >> m;
	memset(like, 0, sizeof(like));
	for(ll i = 1; i <= n; i++){
		cin >> k;
		for(ll j = 1; j <= k; j++){
			cin >> a;
			like[i][a] = true;
		}
	}
 
	ll ans = 0;
	for(ll j = 1; j <= m; j++){
		bool flag = true;
		for(ll i = 1; i <= n; i++){
			if(!like[i][j]){flag = false;}
		}
		if(flag){ans++;}
	}
 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int p;
    int sum = 0;
    for (int i=0;i<n;i++){
        cin >> p;
        if (p!=i+1){
            sum++;
        }
    }
    if (sum<=2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 256