akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
long long GCD(long long a1,long long a2);
long long LCM(long long a1,long long a2);
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    long long n;
    cin>>n;
    long long a1,a2;
    cin>>a1;
    for(int i=0;i<n-1;i++){
        cin>>a2;
        a1=LCM(a1,a2);
    }
    cout<<a1<<endl;
}
long long GCD(long long a1,long long a2){
    while(a2!=0){
        long long r=a1%a2;
        a1=a2;
        a2=r;
    }
    return(a1);
}
long long LCM(long long a1,long long a2){
    return a1/GCD(a1,a2)*a2;
}


Measured memory_bytes: 3216
// https://atcoder.jp/contests/abc159/tasks/abc159_b
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>

using namespace std;

bool palindrome(string s) {
	string t = s; reverse(s.begin(), s.end());
	//cout << t << "-" << s << endl;
	return s == t;
}

string s;

int main() {
	cin >> s;
	//cout << s.substr(0, s.length() - 1 >> 1)    << endl;
	//cout << s.substr((s.length() + 3 >> 1) - 1) << endl;
	if (s.length() & 1 							        &&
		palindrome(s)     							    &&
		palindrome(s.substr(0, s.length() - 1 >> 1))    &&
		palindrome(s.substr((s.length() + 3 >> 1) - 1)) 
	   ) puts("Yes");
	else puts("No");
	
	return 0;
}

Measured memory_bytes: 256
import static java.lang.Math.abs;
import static java.lang.Math.min;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Locale;
import java.util.Scanner;

public class Main {

	final static int INF = Integer.MAX_VALUE;

	public static void main(String[] args) {
		Locale.setDefault(Locale.ENGLISH);
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		solve(in, System.out);
		in.close();
	}

	protected static void solve(Scanner in, PrintStream out) {
		int n = in.nextInt();
		int[] a = new int[n];
		for (int j = 0; j < n; j++) {
			a[j] = in.nextInt();
		}
		int ret = solveLine(n, a);
		out.printf(Locale.ENGLISH, "%s%n", ret);
	}

	private static int solveLine(int n, int[] ar) {
		int[] dp = new int[n + 2];
		Arrays.fill(dp, INF);
		dp[0] = 0;
		for (int i = 0; i < n - 1; i++) {
			dp[i + 1] = min(dp[i + 1], dp[i] + abs(ar[i] - ar[i + 1]));
			if (i < n - 2) dp[i + 2] = min(dp[i + 2], dp[i] + abs(ar[i] - ar[i + 2]));
		}
		return dp[n - 1];
	}

}

Measured memory_bytes: 49648
#include<bits/stdc++.h>
using namespace std;
#define nl printf("\n");

int main()
{
// #ifndef ONLINE_JUDGE
//   freopen("input.txt","r",stdin);
// #endif
    int a,b;
    cin>>a>>b;
    int sum=a+b;
    cout<<6-sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int r = 0;
	int b = 0;
	rep(i, n) {
		if (s[i] == 'R') {
			r++;
		}
		else {
			b++;
		}
	}
	if (r > b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
from itertools import groupby
S = input()
K = int(input())
a = [len(tuple(s)) for _, s in groupby(S)]
ans = 0
 
if S[0] == S[-1] and K > 1:
    if len(a) == 1:
        ans = a[0]*K // 2
    else:
        ans = a[0] // 2 + a[-1] // 2 + (a[0]+a[-1]) // 2 * (K-1)
        ans += sum(n // 2 for n in a[1:-1]) * K
else:
    ans = sum(n // 2 for n in a) * K
print(ans)

Measured memory_bytes: 3064
// AOJ 0615 Cake 2
// 2018.2.27 bal4u

#include <stdio.h>

int a[2002];
long long dp[2002][2002];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, f, i, l, r, nl, nr;
	long long k, ans;

	n = in();
	for (i = 0; i < n; i++) a[i] = in();

	f = (n-1) & 1;
	for (i = 0; i < n; i++, f = !f) {
		nl = 0, r = i-1, nr = i-2;
		for (l = 0; l < n; l++) {
			if (++ r == n)  r = 0;
			if (++nl == n) nl = 0;
			if (++nr == n) nr = 0;

			if (f) {
				if (a[l] > a[r]) dp[l][r] = dp[nl][r];
				else             dp[l][r] = dp[l][nr];
	        } else {
				dp[l][r] = dp[nl][r] + a[l];
				       k = dp[l][nr] + a[r];
				if (k > dp[l][r]) dp[l][r] = k;
			}
		}
	}

	ans = 0;
	r = n-2; for (l = 0; l < n; l++) {
		if (++r == n) r = 0;
		if (dp[l][r] > ans) ans = dp[l][r];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 32980
def fact(n,mod):
    sm=1
    for i in range(2,n+1):
        sm*=i
        sm%=mod
    return sm

def main():
    mod=10**9+7
    x,y=map(int,input().split())
    if (x+y)%3!=0 : print(0);exit()
    times=(x+y)//3

    xwork,ywork=(x-times,y-times)

    if xwork<0 or ywork<0 : print(0);exit()

    sm=fact(times,mod)
    sm*=pow(fact(xwork,mod),mod-2,mod=mod)
    sm%=mod
    sm*=pow(fact(ywork,mod),mod-2,mod=mod)
    sm%=mod

    print(sm)

main()

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

int A, B;
int a[28];
int b[28];

int c[5][5][5];
int nc[5][5][5];

bool in(int x, int y, int z) {
	return 0 <= x && x < 5 && 0 <= y && y < 5 && 0 <= z && z < 5;
}

void sim() {
	memset(nc, 0, sizeof nc);

	for(int z = 0; z < 5; z++) {
		for(int y = 0; y < 5; y++) {
			for(int x = 0; x < 5; x++) {
				int cnt = 0;
				for(int dx = -1; dx <= 1; dx++) {
					for(int dy = -1; dy <= 1; dy++) {
						for(int dz = -1; dz <= 1; dz++) {
							if(dx == 0 && dy == 0 && dz == 0) continue;
							int nx = x + dx, ny = y + dy, nz = z + dz;
							if(!in(nx, ny, nz)) continue;
							cnt += c[nz][ny][nx];
						}
					}
				}
				if(c[z][y][x] == 0) {
					if(a[cnt]) nc[z][y][x] = 1;
					else nc[z][y][x] = 0;
				}
				else {
					if(b[cnt]) nc[z][y][x] = 1;
					else nc[z][y][x] = 0;
				}
			}
		}
	}

	memcpy(c, nc, sizeof c);
}

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

	int N;
	int Case = 1;
	while(cin >> N, N) {
		for(int i = 0; i < 5; i++) {
			for(int j = 0; j < 5; j++) {
				for(int k = 0; k < 5; k++) {
					char ch;
					cin >> ch;
					c[i][j][k] = ch - '0';
				}
			}
		}

		memset(a, 0, sizeof a);
		memset(b, 0, sizeof b);
		cin >> A;
		for(int i = 0; i < A; i++) {
			int x;
			cin >> x;
			a[x] = 1;
		}
		cin >> B;
		for(int i = 0; i < B; i++) {
			int x;
			cin >> x;
			b[x] = 1;
		}

		for(int i = 0; i < N; i++) {
			sim();
		}

		if(Case != 1) cout << endl;
		cout << "Case" << " " << Case << ":" << endl;
		for(int i = 0; i < 5; i++) {
			for(int j = 0; j < 5; j++) {
				for(int k = 0; k < 5; k++) {
					cout << c[i][j][k];
				}
				cout << endl;
			}
			if(i != 4) cout << endl;
		}
		Case++;
	}

}

Measured memory_bytes: 3184
#include<iostream>
#include<vector>
#include<cmath>
#define Number 100000
using namespace std;

int main(){
  vector<int> pri;
  bool prime_table[Number]={0};
  for(int i=2;i<Number;i++){
    if(!prime_table[i]){
      pri.push_back(i);
      for(int j=i+i;j<Number;j+=i)
	prime_table[j]=1;
    }
  }

  int m,a,b;
  while(cin>>m>>a>>b,m){
    int s=(int)pri.size();
    int half=sqrt(m);
    int p=0,q=0;
    int ma=0;
    for(int i=0;i<s;i++){
      if(pri[i]<=half){
	for(int j=i;j<s;j++){
	  int k=pri[i]*pri[j];
	  if(((double)a/b <= (double)pri[i]/pri[j]) && (k <= m) && (ma < k)){
	    ma=k;
	    p=pri[i];
	    q=pri[j];
	  }
	}
      }
    }
    cout<<p<<" "<<q<<endl;
  }
  return 0;
}

Measured memory_bytes: 1420
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int main(){
	int n;
	scanf("%d",&n);
	int a[n];
	int f = 0;
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
		if(a[i] == 1) f = 1;
	}
	if(!f) printf("-1\n");
	else{
		int p = 1;
		int cnt = 0;
		for(int i = 1;i <= n;i++){
			if(a[i] == p){
				cnt++;
				p++;
			}
		}
		printf("%d\n",n-cnt);
	}	
	return 0;
} 

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <limits>
#include <utility>
#include <algorithm>

int main(int argc, char *argv[])
{
    int n, m;
    int num[3] = {-1, -1, -1};
    bool exist = true;

    std::cin >> n >> m;

    for (int i = 0; i < m; i++) {
        int s, c;
        std::cin >> s >> c;

        if (s > n) {exist = false; continue;}
        if ((num[s - 1] != -1)&&(num[s - 1] != c)) {exist = false; continue;}
        if ((n > 1)&&(s == 1)&&(c == 0)) {exist = false; continue;}

        num[s - 1] = c;
    }

    if ((n > 1)&&(num[0] == -1)) {num[0] = 1;}
    for (int i = 0; i < 3; i++) {
        if (num[i] == -1) {num[i] = 0;}
    }

    if (exist) {
        const int mul[6] = {0, 0, 0, 1, 10, 100};
        const int ans = num[2] * mul[n] + num[1] * mul[n + 1] + num[0] * mul[n + 2];
        std::cout << ans << std::endl;
    } else {
        std::cout << -1 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
program main
  implicit none
  integer :: h, w, x, y, l, r
  character(2000) :: s(2000)
  integer, allocatable :: tate(:, :), yoko(:, :)
  read (*, *) h, w
  allocate (tate(w, h), yoko(w, h))
  do y = 1, h
    read (*, *) s(y)
  end do
  yoko = 0
  tate = 0
  do y = 1, h
    do l = 1, w
      if ((l == 1 .or. s(y)(l - 1:l - 1) == "#") .and. s(y)(l:l) == ".") then
        do r = l, w
          if (r == w .or. s(y)(r + 1:r + 1) == "#") exit
        end do
        do x = l, r
          yoko(x, y) = r - l + 1
        end do
      end if
    end do
  end do
  do x = 1, w
    do l = 1, h
      if ((l == 1 .or. s(l - 1)(x:x) == "#") .and. s(l)(x:x) == ".") then
        do r = l, h
          if (r == h .or. s(r + 1)(x:x) == "#") exit
        end do
        do y = l, r
          tate(x, y) = r - l + 1
        end do
      end if
    end do
  end do
  print "(i0)", maxval(yoko + tate - 1)
end program main


Measured memory_bytes: 35328
#include<bits/stdc++.h>
using namespace std;
int a[100001][4];
int f[100001][4];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d %d",&a[i][1],&a[i][2],&a[i][3]);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=3;j++)
		{
			for(int k=1;k<=3;k++)
			{
				if(k!=j)
					f[i][j]=max(f[i][j],f[i-1][k]+a[i][j]);
			}
		}
	}
	int max_=0;
	for(int i=1;i<=3;i++)
	{
		if(f[n][i]>max_)
			max_=f[n][i];
	}
	printf("%d",max_);
	return 0;
}

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

int main()
{
	string a;
	int awal=0,akhir=0;
	getline(cin,a);
	for(int i=0;i<a.length();i++)
	{
		if(a[i]=='A')
		{
			awal = i;
			break;
		}
		
	}
	for(int i=awal;i<a.length();i++)
	{
		if(a[i]=='Z')
		{
			akhir=i;
		}
	}
	cout << akhir - awal+1 << endl;
}

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

using namespace std;

int main() {
  int64_t D, T, S;
  cin >> D >> T >> S;
  if (S * T >= D) {
    cout << "Yes" << endl; 
  } else {
    cout << "No" << endl; 
  }
  return 0;
}


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

using namespace std;

int main()
{
	long long n;
	cin>>n;
	long long arr[n];
	long long MAX=INT_MIN,MAX2=INT_MIN,cnt=0;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		MAX=max(arr[i],MAX);
	}
	for(int i=0;i<n;i++)
	{
		if(arr[i]==MAX)
		{
			cnt+=1;
		}
		else
		{
			MAX2=max(arr[i],MAX2);
		}
	}
	if(cnt>1)
	{
		while(n--)
		{
			cout<<MAX<<endl;
		}
	}
	else
	{
	for(int i=0;i<n;i++)
	{
		if(arr[i]==MAX)
			cout<<MAX2<<endl;
		else
			cout<<MAX<<endl;
	}
	}


}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<ll> l(n + 1), r(n + 1);
  for (int i = 0; i < n; i++) r[i + 1] = r[i] + a[i];
  for (int i = 0; i < n; i++) l[i + 1] = l[i] + a[n - 1 - i];
  ll ans = 1000000000000000LL;
  for (int i = 0; i <= n; i++) {
    ans = min(ans, abs(r[i] - l[n - i]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

/*プロセスを表す構造体*/
typedef struct pp{
    char name[100];
    int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) {return a < b ? a : b;} /*最小値を返す*/

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
    /*すべてのプロセスをキューに順番に追加する*/
    for(i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1;
    tail = n + 1;

    /*シミュレーション*/
    while(head != tail){
        u = dequeue();
        c = min(q, u.t); /*q または必要な時間 u.t だけ処理を行う*/
        u.t -= c; /*残りの必要時間を計算*/
        elaps += c; /*経過時間を加算*/
        if(u.t > 0) enqueue(u); /*処理が完了していなければキューに追加*/
        else printf("%s %d\n", u.name, elaps);
    }

    return 0;
}


Measured memory_bytes: 11936
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
C.sort(reverse=True)
E=[]
ans=[]
for i in range(X):
    for j in range(Y):
        E.append(A[i]+B[j])
E.sort(reverse=True)
for i in range(min(K,len(E))):
    for j in range(min(K,Y)):
        ans.append(E[i]+C[j])
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])


Measured memory_bytes: 148672
// BROWNIE TK
 
#include <bits/stdc++.h>
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
 
#define forz(i, n) for (int i = 0; i < n; i++)
#define bui(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define mui(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
 
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define osetlli tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order

using namespace std;
 
/*STD fucntions*/
lli power(lli x,lli y,lli p)
{
    lli res=1;
    x=x%p;
    while(y>0)
    {
        if(y&1)
            res=(res*x)%p;
        //y must be even now
        y=y>>1; //y=y/2
        x=(x*x)%p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{ return a * b / gcd(a, b); }
lli modi(lli a,lli m)
{
// fermat little thm where m is prime
return power(a,m-2,m);
}
/*CODE BEGINS*/
int main()
{
 kira;
 lli n,w;
 cin>>n>>w;
 lli wt[n+1],val[n+1];
 lli s=0;
 for(int i=1;i<=n;i++)
 {
   cin>>wt[i]>>val[i];
   s+=val[i];
 }
 lli INF=1e18+5;
 vector<lli>dp(s+1,INF);
 dp[0]=0;
 for(int i=1;i<=n;i++)
 {
   for(int j=s;j>=val[i];j--)
   {
     dp[j]=min(dp[j],dp[j-val[i]]+wt[i]);
   }
 }
 lli ans=0;
 forz(i,s+1)
 {
   if(dp[i]<=w){
     ans=max(ans,lli(i));}
 }
 cout<<ans;
 return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
int main() {
  int n;
  cin >> n;
  ll ans[10005] = {};
  for (ll x = 1; x * x <= n; x++) {
    for (ll y = 1; y * y <= n; y++) {
      for (ll z = 1; z * z <= n; z++) {
        ll value = x * x + y * y + z * z + x * y + y * z + z * x;
        if (value <= n) {
          ans[value]++;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3524
k=int(input())
lst=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(lst[k-1])

Measured memory_bytes: 2940
from functools import reduce
while True:
	n = input()
	if n == "0000":
		break
	n = n if len(n) >= 4 else n.zfill(4)
	if reduce(lambda x,y:x and y,[n[0] == i for i in n]):
		print("NA")
	else:
		cnt = 0
		while n != "6174":
			s = ''.join(sorted(n))
			l = ''.join(sorted(n,reverse = True))
			n = str(int(l)-int(s))
			n = n if len(n) >= 4 else n.zfill(4)
			cnt += 1
		print(cnt)

Measured memory_bytes: 8300
#include <iostream>
#include <string>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <climits>
#include <numeric>
#include <algorithm>
#include <cassert>

using namespace std;

int main()
{
    int n,x,y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<vector<int>> distances(n, vector<int>(n, 0));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < i; ++j){
            distances[i][j] = distances[j][i] = min({abs(i-j), abs(i-x) + abs(y-j) + 1, abs(i-y) + abs(x-j) + 1});
        }
    }
    /*
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= i; ++j){
            cout << distances[i][j] << ',';
        }
        cout << '\n';
    }
    */
    vector<int> count(n);
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            count[distances[i][j]] += 1;
        }
    }
    for(int i = 1; i < n; ++i){
        cout << count[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 16000
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')
def pprint(M):
	for row in M:
		print(row)
	print("~~~")


def main():
	n, W = rli()
	weights, vals = [], []
	for _ in range(n):
		w, v = rli()
		weights.append(w)
		vals.append(v)
	maxval = 10**5 + 100
	dp = [INF for _ in range(maxval+1)]
	dp[0] = 0
	for w, v in zip(weights, vals):
		for i in range(maxval, -1, -1):
			if i - v < 0: continue
			dp[i] = min(dp[i], dp[i-v] + w)
	for i in range(maxval, -1, -1):
		if dp[i] <= W:
			print(i)
			break
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 83080
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {
        return cost < e.cost;
    }
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int ans;
vector<Edge<ll>> es;
vector<int> G[2505];
ll dist[2505];
bool cyc[2505];

int main(void) {
    int N, M;
    ll P;
    cin >> N >> M >> P;
    rep(i, 0, M) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--, b--;
        Edge<ll> e(a, b, c-P);
        es.pb(e);
        G[a].pb(b);
    }
    rep(i, 0, N) dist[i] = -LINF;

    dist[0] = 0;
    rep (i, 0, N) {
        for (int i=0; i<M; i++) {
            Edge<ll> e = es[i];
            if (dist[e.u]!=-LINF && dist[e.v]<dist[e.u]+e.cost) {
                dist[e.v] = dist[e.u]+e.cost;
            }
        }
    }
    
    queue<int> q;
    
    for(int i=0; i<M; i++) {
      Edge<ll> e = es[i];
      if (dist[e.u]!=-LINF && dist[e.v]<dist[e.u]+e.cost) {
                dist[e.v] = dist[e.u]+e.cost;
                cyc[e.v]=cyc[e.u] = true;
                q.push(e.u), q.push(e.v);
       }
    }
    
    while(!q.empty()) {
      int u = q.front(); q.pop();
      for (int v : G[u]) {
        if (!cyc[v]) {
          cyc[v] = true;
          q.push(v);
        }
      }
    }
    
    
   
    if (cyc[N-1]) puts("-1");
    else cout << max(0LL, dist[N-1]) << "\n";
    return 0;
}




Measured memory_bytes: 3828
N = int(input())
scores = []
for _ in range(N):
    scores.append(int(input()))
scores.sort()
s = sum(scores)
if s%10 != 0:
    print(s)
    exit()
for i in scores:
    if i %10 != 0:
        print(s-i)
        exit()
else:
    print(0)

Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

inline int sgn(const int &n) { return n ? 1 : -1; }

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	struct para { 
		lint x, y, z; 
		para() :x(0), y(0), z(0) {};
		para operator += (const para &rhs) { x += rhs.x, y += rhs.y, z += rhs.z; return *this; }
		lint pabs() { return abs(x) + abs(y) + abs(z); };
	};
	vector<para> cake(N);
	for (int i = 0; i < N; i++) cin >> cake[i].x >> cake[i].y >> cake[i].z;

	lint ans = 0;

	for (int bit = 0b0; bit < 8; bit++) {
		para sum;
		sort(cake.begin(), cake.end(), [&](para a, para b) { 
			return sgn(bit&4)*a.x + sgn(bit&2)*a.y + sgn(bit&1)*a.z > sgn(bit&4)*b.x + sgn(bit&2)*b.y + sgn(bit&1)*b.z;
		});
		for (int i = 0; i < M; i++) { sum += cake[i]; }
		ans = max(ans, sum.pabs());
	}

	cout << ans << "\n";

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}

//a,b x
int main(){
	ll N; cin>>N;
	vector<ll> A(N+1);
	rep1(i,N) cin>>A[i];
	ll l=1,r=1,xsum=A[1],sum=A[1],ans=0;
	while(1){
		while(sum==xsum && r<N){
			r++;
			xsum^=A[r];
			sum+=A[r];
		}
		if(sum!=xsum){
			xsum^=A[r];
			sum-=A[r];
			r--;
		}
		ans+=(r-l+1);
		if(l==N) break;

		xsum^=A[l];
		sum-=A[l];
		l++;
	}
	cout<<ans;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
bool c(int x,int y){
    return y<x;
}
int main() {
    int n;cin>>n;
    vector<int > p(n);
    for (int i = 0; i < n; ++i)
        cin>>p[i];
    int m;cin>>m;
    vector<int > q(m);
    for(int i=0;i<m;++i)
        cin>>q[i];
    if(lexicographical_compare(p.begin(),p.end(),q.begin(),q.end())){
        cout<<1<<endl;
    }
    else cout<<0<<endl;
    return 0;
}



Measured memory_bytes: 3100
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
#include <iomanip>
 
using namespace std;

int gcd(int a, int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

int tgcd(int a, int b, int c){
  int d = gcd(a, b);
  return gcd(c, d);
}

int main(){
  int K, tri, dub, mon;
  cin >> K;
  tri = K*(K+1) / 2;
  dub = 0;
  for (int i=1;i<K+1;i++){
    for (int j=1;j<K+1;j++){
      if (i < j){
        dub = dub + gcd(i, j);
      }
    }
  }
  mon = 0;
  for (int i=1;i<K+1;i++){
    for (int j=1;j<K+1;j++){
      for (int l=1;l<K+1;l++){
        if (i < j and j < l){
          mon = mon + tgcd(i, j, l);
        }
      }
    }
  }
  cout << tri+6*(mon+dub);
  return 0;  
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

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

    vector<vector<int>> roads(n+1, vector<int>());
    rep(i, m){
        int a, b;
        cin >> a >> b;
        roads[a].emplace_back(b);
        roads[b].emplace_back(a);
    }

    repi(i, 1, n+1){
        cout << roads[i].size() << endl;
    }
}

Measured memory_bytes: 256
from collections import deque
S = input()
left = deque([0])
right = deque([0])
cnt = 0
for s in S:
    if s == '<':
        cnt += 1
    else:
        cnt = 0
    left.append(cnt)
cnt = 0
for s in S[::-1]:
    if s == '>':
        cnt += 1
    else:
        cnt = 0
    right.appendleft(cnt)
ans = 0
for l, r in zip(left, right):
    ans += max(l, r)
print(ans)


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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

struct Doubling {
    const int LOG;
    vector<vector<int> > table;

    Doubling(int sz, int64_t lim_t) : LOG(64 - __builtin_clzll(lim_t)) {
        table.assign(LOG, vector<int>(sz, -1));
    }

    void set_next(int k, int x) {
        table[0][k] = x;
    }

    void build() {
        for (int k = 0; k + 1 < LOG; k++) {
            for (int i = 0; i < table[k].size(); i++) {
                if (table[k][i] == -1) table[k + 1][i] = -1;
                else table[k + 1][i] = table[k][table[k][i]];
            }
        }
    }

    int query(int k, int64_t t) {
        for (int i = LOG - 1; i >= 0; i--) {
            if ((t >> i) & 1) k = table[i][k];
        }
        return k;
    }
};

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

    vector<ll> v(n);
    rep(i, n) cin >> v[i], v[i]--;

    Doubling doubling(n, k);
    rep(i, n) doubling.set_next(i, v[i]);
    doubling.build();

    cout << doubling.query(0, k) + 1 << endl;
}


Measured memory_bytes: 52540
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int table[N+1] = {};
    rep(i,0,N){
        int x;
        cin >> x;
        table[x]++;
    }
    ll ans = 1;
    rep(i,0,N/2){
        ans = (ans * 2 % MOD);
    }
    rep(i,0,N+1){
        //奇数
        if(N % 2){
            if((i % 2 == 0 && i != 0) && table[i] != 2 ||
               i == 0 && table[0] != 1){
                   ans = 0;
               }
        }else{
            if(i % 2 == 1 && table[i] != 2){
                ans = 0;
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
  int h,w,n;
  cin >> h >> w >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  int cnth = 0;
  int cntw = 0;
  string tmp = "";
  vector<vector<int>> anss(h,vector<int>());
  for (int i = 0; i < n; i++)
  {
    int ai = a[i];
    for (int j = 0; j < ai; j++)
    {
      anss[cnth].push_back(i+1);
      cntw++;
      if(cntw%w==0){
        cnth++;
        tmp="";
      }
    }
  }
  for (int i = 0; i < h; i++)
  {
    if (i%2==1) reverse(anss[i].begin(),anss[i].end());
    for (int j = 0; j < w; j++)
    {
      cout << anss[i][j] << " ";
    }
    cout << endl;
  }  
}

Measured memory_bytes: 384
#include <cstdio>
#include <limits>
#include <algorithm>

int n, arr[100010];
constexpr int inf = std::numeric_limits<int>::max();
int main() {
    int i;
    scanf("%d", &n);
    std::fill(arr, arr + n, inf);
    
    int tmp, len = 0;
    for(i = 0; i < n; ++i) {
        scanf("%d", &tmp);
        
        auto * it = std::lower_bound(arr, arr + n, tmp);
        
        *it = tmp;
        
        len = std::max<int>(len, it - arr + 1);
    }
    
    printf("%d\n", len);
}

Measured memory_bytes: 3144
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<double,P> PP;
struct edge { int to; int cost; };
int imos[100006];
signed main() {
	int n, m; cin >> n >> m;
	rep(i, m) {
	
		int l, r; cin >> l >> r;
		imos[l]++;
		imos[r + 1]--;
	}
	rep(i, 100003)imos[i + 1] += imos[i];
	int cnt = 0;
	rep(i, 100003) {
		if (imos[i] == m)cnt++;
	}cout << cnt << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#define ll long long
using namespace std;
int main() 
{
ll n,m;
	scanf("%lld%lld",&n,&m);
ll c=abs((n-2)*(m-2));
printf("%lld\n",c);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int int64;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define F first
#define S second
typedef vector<pli> vpli;
#define hell 1000000007
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define tests int t; cin>>t; while(t--)
#define take(a,b,c) for(b=0;b<c;b++) cin>>a;
#define rep(i,n) for(int i=0;i<n;i++)
#define io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int main(){
  int n;
  cin>>n;
  vector< pair<int,int> > v;
  rep(i,n){
    int a;
    cin>>a;
    v.push_back(make_pair(a,i+1));
  }
  sort(v.begin(),v.end());
  rep(i,n){
    cout<<v[i].S<<" ";
  }
  return 0;
}


Measured memory_bytes: 1780
import sys


def check(S, T):
    count = 0
    for s, t in zip(S, T):
        if s != t:
            count += 1
    return count


def main():
    S = input()
    T = input()
    dif = len(S) - len(T)
    ans = 10000
    for i in range(dif+1):
        compare = S[i: i+len(T)]
        count = check(compare, T)
        if count < ans:
            ans = count

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 8948
#include <stdio.h>
#include <math.h>

int main(){

  double r,S,L,e=3.141592653589;

  scanf("%lf", &r);

  S = e*r*r;

  L = 2*e*r;

  printf("%.5lf %.5lf\n",S,L);

  return 0;

}

Measured memory_bytes: 652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
int main(void){

    int a, b, t;
    cin >> a >> b >> t;
    
    int result = 0;
    for(int i=a; i<=t; i+=a) {
        result += b;
    }

    cout << result << endl;

    return 0;
    
}


Measured memory_bytes: 256
while True:
    try:
        C1, C2, C3 = map(int, input().split())
    except:
        break
    cards = [v for v in range(1, 11)]
    p = []
    for v in [C1, C2, C3]:
        cards.remove(v)
    for i in cards:
        _card = cards[:]
        _card.remove(i)
        for j in _card:
            if C1+C2+j <= 20:
                p.append(1)
            else:
                p.append(0)
    print("YES" if sum(p)/len(p) >= 0.5 else "NO")

Measured memory_bytes: 7700
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, ac = 0, wa = 0, tle = 0, re = 0;
  cin >> N;
  
  for(int i = 0; i < N; i++){
    string s;
    cin >> s;
    if(s == "AC"){
      ac++;
    }else if(s == "WA"){
      wa++;
    }else if(s == "TLE"){
      tle++;
    }else{
      re++;
    }
  }
 
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  map<char , int>count;
  string str;
  while( cin>>str ){
    for(int i=0;i<(int)str.size();i++){
      if(isupper(str[i])){
	str[i]=tolower(str[i]);
      }
    }
    
    for(int i=0;i<(int)str.size();i++){
      count[ str[i] ]++;
    }
  }

  for(char ch='a';ch<='z';ch++){
    cout<<ch<<" "<<":"<<" "<<count[ch]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3148
N = int(input())
s = [0] * N
for i in range(N):
    s[i] = int(input())

sum_s = sum(s)
sort_s = sorted(s)

if sum_s % 10 != 0:
    print(sum_s)
else:
    for i in sort_s:
        if i % 10 == 0:
            continue
        else:
            print(sum_s - i)
            exit()
    print(0)

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

using namespace std;

int main() {
    double sq[11];
    while (scanf("%lf", &sq[1]) != EOF) {
        double ans = sq[1];

        for (int i = 2; i <= 10; i++) {
            if (i % 2) sq[i] = sq[i - 1] / 3.0;
            else sq[i] = sq[i - 1] * 2.0;
            ans += sq[i];
        }

        printf("%.10f\n", ans);
    }

    return 0;
}


Measured memory_bytes: 3192
import java.util.*;
import java.io.*;
import java.math.*;
	        class Main {
	    	static void solve(int[] arr, int n) {
	    	}
	        public static void main(String args[]) throws IOException {
	        	FastReader sc = new FastReader();
	        		int n = sc.nextInt(), x = sc.nextInt(), t = sc.nextInt();
	        		
	        		if(n%x == 0 )  {
	        			pn(n/x*t);
	        		}
	        		else {
	        			pn((n/x + 1)*t);	
	        		}
	       }
	       static void p(Object p){System.out.print(p);}
	       static void pn(){System.out.println();}
	       static void pn(Object o){System.out.println(o);}
	       
	       static class FastReader {
	       static BufferedReader br;
	       StringTokenizer st;
	       public FastReader() {
	       br = new BufferedReader(new InputStreamReader(System.in));
	       }
	            
	       String next(){
	       while (st == null || !st.hasMoreElements()) {
	            try{
	                st = new StringTokenizer(br.readLine());
	            }
	            catch (IOException  e) {
	                e.printStackTrace();
	            }}
	            return st.nextToken();
	            }
	            
	            int nextInt(){ 
	                return Integer.parseInt(next());
	            }
	            
	            long nextLong(){ 
	                return Long.parseLong(next());
	            }
	            
	            static int max(int[] a){
	            int max = Integer.MIN_VALUE;
	            for(int i : a) max = Math.max(max, i);
	            return max;
	            }
	            
	            public int[] readIntArray(int n) {
	            int[] arr = new int[n];
	            for(int i=0; i<n; ++i) arr[i]=nextInt();
	            return arr;
	            }
	            
	            public long[] readLongArray(int n){
	            long[] arr = new long[n];
	            for(int i=0; i<n; ++i) arr[i]=nextLong();
	            return arr;
	            }
	            
	            public int[][] readIntArray(int m, int n){
	            int[][] arr = new int[m][n];
	            for(int i = 0;i<m;i++) 
	            for(int j = 0;j<n;j++) arr[i][j] = nextInt();
	            return arr;
	            }
	            
	            public String[] readStringArray(int n) {
	            String[] arr = new String[n];
	            for(int i=0; i<n; ++i) arr[i]= nextLine();
	            return arr;
	            }
	            
	            double nextDouble() {return Double.parseDouble(next());}
	            
	            String nextLine() {
	            String str = "";
	            try{str = br.readLine();}
	            catch (IOException e) {e.printStackTrace();}
	            return str;}}
	        }


Measured memory_bytes: 32636
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cstring>
#include<string>
#include<iomanip>
#include<map>
#include<fstream>
#include<queue>
#include<stack>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if (a + b >= 10)
		cout << "error" << endl;
	else
		cout << a + b << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<unordered_set>
using namespace std;

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

	cout << N * N - A << endl;
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))

s = sum(a)
s = (s-1)//(4*m) + 1
count = 0
for i in range(n):
    if a[i] >= s:
        count += 1

if count >= m:
    print("Yes")
else:
    print("No")


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

int main(){
    int w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<double(w)*double(h)/2.0<<" "<<(x*2==w&&y*2==h);
    return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n;
	string s;

	cin >> n;

	vector<ll> G[200];

	REP(i, n) {
		cin >> s;

		REP(j, n) {
			if (s[j] == '1') {
				G[i].push_back(j);
			}
		}
	}

	ll ans = -1;

	REP(i, n) {
		ll a = -1;
		queue<ll> q;
		q.push(i);
		vector<ll> dist(n, INF);
		dist[i] = 1;
		while (!q.empty()) {
			ll now = q.front();
			bool flag = false;
			q.pop();
			REP(j, G[now].size()) {
				ll next = G[now][j];
				if (dist[next] != INF) {
					if (abs(dist[next] - dist[now]) != 1) {
						a = -1;
						flag = true;
						break;
					}
					continue;
				}
				dist[next] = dist[now] + 1;
				a = max(a, dist[next]);
				q.push(next);
			}
			if (flag) {
				break;
			}
		}
		ans = max(ans, a);
	}

	cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<fstream>
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
bool winner(int Su,int Pu){
	/*
	int Mu = 0;

	for (int i = Pu; i < Su; i++){
		if (U[i] == u)Mu++;
	}
	*/

	if (Su == 0)return true;
	else return false;
}

char solve(char A[], char B[], char C[], int Sa, int Sb, int Sc, int Pa, int Pb, int Pc, char Tu){

	bool w;

	//printf("T:%c ", Tu);

	if (Tu == 'a')w = winner(Sa, Pa);
	else if (Tu == 'b')w = winner(Sb, Pb);
	else if (Tu == 'c')w = winner(Sc, Pb);

	if (w == true){
		return Tu;
	}
	else {
		if (Tu == 'a'){
			Tu = A[Pa];
			Pa++;
			Sa--;
			return solve(A, B, C, Sa, Sb, Sc, Pa, Pb, Pc, Tu);
		}
		else if (Tu == 'b'){
			Tu = B[Pb];
			Pb++;
			Sb--;
			return solve(A, B, C, Sa, Sb, Sc, Pa, Pb, Pc, Tu);
		}
		else if (Tu == 'c'){
			Tu = C[Pc];
			Pc++;
			Sc--;
			return solve(A, B, C, Sa, Sb, Sc, Pa, Pb, Pc, Tu);
		}
	}

}

int main(){

	char A[101], B[101], C[101];
	int Sa, Sb, Sc;
	int Pa = 0, Pb = 0, Pc = 0;

	for (int i = 0; i < 101; i++){
		A[i] = 0; B[i] = 0; C[i] = 0;
	}

	cin >> A >> B >> C;

	Sa = strlen(A);
	Sb = strlen(B);
	Sc = strlen(C);


	char wi = solve(A, B, C, Sa, Sb, Sc, Pa, Pb, Pc, 'a');

	printf("%c\n", wi-32);

	

	return 0;
}

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

template <typename T>
class FenwickTreeAdd{
  using value_type = T;
  
  int size;
  std::vector<value_type> data;
  
public:
  FenwickTreeAdd(){}
  FenwickTreeAdd(int size): size(size), data(size + 1, 0){}
  
  void update(int i, value_type val){
    i += 1; // 1-index
    
    while(i <= size){
      data[i] = data[i] + val;
      i += i & (-i);
    }
  }
  
  value_type get(int i) const { // [0, i)
    value_type ret = 0;
    i += 1; // 1-index

    while(i > 0){
      ret = ret + data[i];
      i -= i & (-i);
    }

    return ret;
  }

  value_type get(int l, int r) const { // [l, r)
    return get(r-1) - get(l-1);
  }
};


template <typename T>
struct RangeCountQuery{
  std::vector<int> a;
  std::vector<std::pair<int, int>> qs;
  //std::map<std::pair<int, int>, std::vector<int>> index;
  std::unordered_map<int, std::unordered_map<int, std::vector<int>>> index;
  int N;

  RangeCountQuery(std::vector<T> a_): N(a_.size()){
    auto temp = a_;
    std::sort(temp.begin(), temp.end());
    temp.erase(std::unique(temp.begin(), temp.end()), temp.end());

    for(auto x : a_){
      int i = std::lower_bound(temp.begin(), temp.end(), x) - temp.begin(); 
      a.push_back(i);
    }
  }

  void add(int l, int r){ // [l, r)
    //index[{l, r}].push_back(qs.size());
    index[l][r].push_back(qs.size());
    qs.emplace_back(r, l);
  }

  auto solve(){
    std::sort(qs.begin(), qs.end());

    FenwickTreeAdd<int> b(N);

    const int Q = qs.size();
    std::vector<int> last_index(N, -1);
    std::vector<int> ret(Q);
  
    int cur = 0;
    for(auto [r, l] : qs){
      while(cur < r){
        if(last_index[a[cur]] != -1){
          b.update(last_index[a[cur]], -1);
        }

        last_index[a[cur]] = cur;
        b.update(last_index[a[cur]], 1);

        ++cur;
      }

      //for(auto i : index[{l, r}]){
      auto t = index[l][r];
      for(int i : t){
        ret[i] = b.get(l, r);
      }
    }
    
    return ret;
  }
};


int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int N, Q; std::cin >> N >> Q;
  std::vector<int> c(N);
  for(int i = 0; i < N; ++i) std::cin >> c[i];

  RangeCountQuery<int> rcq(c);

  for(int i = 0; i < Q; ++i){
    int l, r; std::cin >> l >> r;
    rcq.add(l - 1, r);
  }

  auto ans = rcq.solve();

  for(auto x : ans) std::cout << x << "\n";

  return 0;
}


Measured memory_bytes: 92616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;

int main(){
    int N,M; //N種類の商品、M個選ぶ。
    cin >> N >> M;
    vector<int> A(N);
    int count=0;
    int sum=0;
    for(int i=0; i<N; i++){
        cin >> A.at(i);
        sum += A.at(i);
    }
    float a = (float)sum/(4*M) ;
    for(int i=0; i<N; i++){
        if(A.at(i)>=a) count++;
    }
    if(count>=M){
        cout << "Yes";
    }else{
        cout << "No";
    }

}

Measured memory_bytes: 256
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

ll gcd(ll a, ll b){
    if (a < b) swap(a,b);
    if (a%b){
        return gcd(b,a%b);
    } else {
        return b;
    }
}

int t;
ll a,b,c,d;

int main(){
    I(t);
    REP(_,t){
        LL(a);
        LL(b);
        LL(c);
        LL(d);
        if (a < b){
            cout << "No" << endl;
            continue;
        }

        ll dgcd = gcd(b,d);
        a %= b;
        a %= dgcd;
        a += b - dgcd;

        if (d >= b && c >= a) { 
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <long long> vll;
typedef vector <vi> vvi;
typedef vector <vll> vvll;
 
#define all(v) v.begin(),v.end()
#define nl endl
#define bs(v,n) binary_search(v.begin(),v.end(),n)
#define sz() size()
#define pb push_back
 
ll mod=10000;

int main() {
	string S;
	cin>>S;
	bool f=true;
	if(S[0]==S[1] and S[2]==S[3] and S[0]!=S[2]){
		cout<<"Yes"<<nl;
		f=false;
	}else if(S[0]==S[2] and S[1]==S[3] and S[0]!=S[1]){
		cout<<"Yes"<<nl;
		f=false;
	}else if(S[0]==S[3] and S[1]==S[2] and S[0]!=S[1]){
		cout<<"Yes"<<nl;
		f=false;
	}
	if(f)cout<<"No"<<nl;
	return 0;
}

Measured memory_bytes: 256