akhauriyash/Code-Regression huggingface dataset:
#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>
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 ;


ll powmod(ll n,ll k,ll m){
	ll ret=1;
	while(k){
		if(k%2)ret=ret*n%m;
		n=n*n%m;
		k/=2;
	}
	return ret;
}
ll gcd(ll x,ll y){
	if(x<y)swap(x,y);
	return y?gcd(y,x%y) : x;
}
ll lcm(ll x,ll y){
	return x/gcd(x,y)*y;
}
int solve(){
	int n;
	cin>>n;
	ll N=n;
	if(n==2)return 1;
	int m=1;
	for(int i=2;i<100000;++i){
		if(n%i==0){
			n/=i;
			if(n%i==0)return -1;
			m=lcm(i-1,m);
		}
	}
	if(n>1)m=lcm(n-1,m);
	ll M=m;
	ll res=m;
	for(int i=2;i<=100000;++i){
		if(m%i==0){
			res/=i;
			res*=(i-1);
			while(m%i==0)m/=i;
		}
	}
	if(m>1){
		res/=m;
		res*=m-1;
	}
	ll ans=1e9;
	for(ll i=1;i<=100000;++i){
		if(res%i==0){
			if(powmod(N,i,M)==1)ans=min(ans,i);
			if(powmod(N,res/i,M)==1)ans=min(ans,res/i);
		}
	}
	if(ans<1e9)return ans;
	return -1;
}

int main(){
	cout<<solve()<<endl;
}


Measured memory_bytes: 3096
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int A = sc.nextInt();
   int B = sc.nextInt();
   int K = sc.nextInt();

   if(B>A)
   {
    int s =B;
    B = A;
    A = s;
   }
   
   int count =0;
   int ans=0;
   int cd = B;
   while(count<K)
   {
     if(A%cd==0 && B%cd ==0) 
     {
       count++;
       ans = cd;
     }
     cd--;
   }
   System.out.println(ans);
 }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

int n;

bool isin(int l, int r, int x) {
	if (l > r)swap(l, r);
	return l <= x && x <= r;
}

ld isy(int l, int r, int ly, int ry, int x) {
	ld dy = ry - ly;
	ld dx = r - l;
	return dy * (x - l) / dx + ly;

}

const int mn = 2000;

void solve() {
	vector<int> x(n), y(n);
	rep(i, n) {
		cin >> x[i] >> y[i];
	}
	x.push_back(x[0]);
	y.push_back(y[0]);
	int ans = 0;
	for (int i = -mn; i < mn; i++) {
		vector<LDP> v;
		rep(j, n) {
			if (x[j] == x[j + 1])continue;
			int lx = x[j], rx = x[j + 1];
			int ly = y[j], ry = y[j + 1];
			if (lx > rx) {
				swap(lx, rx);
				swap(ly, ry);
			}
			if (lx <= i && i + 1 <= rx) {
				ld le = isy(lx, rx, ly, ry, i);
				ld ri = isy(lx, rx, ly, ry, i + 1);
				v.push_back({ le,ri });
			}
		}
		sort(v.begin(), v.end());
		vector<int> exi(2 * mn + 2, 0);
		rep(j, v.size()) {
			ld le = min(v[j].first, v[j].second);
			ld ri = max(v[j + 1].first, v[j + 1].second);
			int l = le +2*mn+ eps;
			int r = ri+2*mn - eps;
			l -= 2*mn; r -= 2*mn;
			//cout << i << " " << le << " " << ri << endl;
			//cout << i << " " << l << " " << r << endl;
			//cout << "?? " << i << " " << v[j + 1].second << endl;
			exi[l+mn]++; exi[r + 1+mn]--;
			j++;
		}
		int memo = ans;
		rep(j, 2 * mn + 1) {
			exi[j + 1] += exi[j];
			if (exi[j])ans++;
		}
		//cout << i << " " << ans - memo << endl;
	}
	//cout << "ans is ";
	cout << ans << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	while (cin >> n, n) {
		solve();
	}
	//stop
		return 0;
}




Measured memory_bytes: 3148
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace __gnu_pbds;
using namespace std;
 
const int MAXN = 1000 + 20, MAXM = 20, MOD = 1000 * 1000 * 1000 + 7;
const long long INF = 1e9 + 10;
char c[MAXN][MAXN];
int a[MAXN];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int n, m;
map <int, int> m1;

bool ok(int x, int y) {
	return (x >= 0 && x < n && y >= 0 && y < m);
}

void solve() {
	int n;
	cin >> n;
	
	for (int i = 0; i < n; i++)
		cin >> a[i];
		
	bool nob = 0;
	while (1) {
		int mn = INF, sum = 0, od = 0, ev = 0;
		for (int i = 0; i < n; i++) {
			sum += a[i];	
			mn = min(a[i], mn);
			od += a[i] % 2;
			ev += (a[i] - 1) % 2;
		}
		
		if (mn == 1) {
			if (nob == 0) {
				if ((sum - n) % 2 == 1) 
					cout << "First" << endl;
				else
					cout << "Second" << endl;
			}
			else {
				if ((sum - n) % 2 == 0) 
					cout << "First" << endl;
				else
					cout << "Second" << endl;
			}
			return;
		}
		else {
			int cnt = 0;
			int g = 0;
			if (ev % 2 == 1) {
				if (nob == 0)
					cout << "First" << endl;
				else
					cout << "Second" << endl;
				return;
			}
			if (od > 1) {
				if (nob == 1)
					cout << "First" << endl;
				else
					cout << "Second" << endl;
				return;
			}
			
			for (int i = 0; i < n; i++) {
				if (a[i] % 2 == 1) {
					cnt++;
					a[i]--;
				}
				g = __gcd(g, a[i]);
			}
			for (int i = 0; i < n; i++)	
				a[i] /= g;
			
			nob ^= 1;
		}
	}
}
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	solve();
}

Measured memory_bytes: 4012
#include <iostream>

using namespace std;

int main(){
	int two[15]={},n,cnt=-1,check[15]={},last=0;
	for(int i=0;i<11;i++){
		two[i]=1;
		for(int j=0;j<i;j++)two[i]*=2;
	}
	while(cin>>n){
		cnt=0;
		last=0;
		for(int i=0;i<10;i++){
			check[i]=0;
			if(n<two[i+1]){
				cnt=i;
				break;
			}
		}
		for(int i=cnt;i>=0;i--){
			if(n%2==1)check[i]++;
			n/=2;
		}
		for(int i=0;i<10;i++){
		if(check[i]==1){
			last=i;
			break;
		}
		}
		for(int i=cnt;i>=last;i--){
			if(check[i]==1&&last!=i)cout<<two[cnt-i]<<" ";	
			else if(i==last)cout<<two[cnt]<<endl;
		}
	}
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n,count = 0;;
	char c[1000];
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> c[i];
	}
	for(int i = 0; i < n; i++){
		if(c[i] != '0'){
			for(int j = i+1; j < n; j++){
				if(c[i] == c[j]) c[j] = '0';
			}
			c[i] = '0';
			count++;
		}
	}
	if(count == 4) cout << "Four" << endl;
	else cout << "Three" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp
#include <numeric>

using namespace std;

// ユークリッド互除法の最大公約数の実装コピペ
int gcd(int m, int n) {
  if ( ( 0 == m ) || ( 0 == n ) )
    return 0;

  while( m != n )
  {
    if ( m > n ) m = m - n;
    else         n = n - m;
  }
  return m;
}

int main() {
  int x, y;
  cin >> x >> y;
  // 考察より x + y - gcd(x, y) + 1
  cout << (x + y - gcd(x, y) + 1) << endl;
}



Measured memory_bytes: 3104
#include<cstdio>
#include<cmath>
#include<iostream>

using namespace std;

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-b)<=d&&abs(c-b)<=d||abs(c-a)<=d)
		printf("Yes");
	else printf("No");
	return 0;
 }

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<map>
using namespace std;
typedef pair<int, pair<int, int> >PP;
typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec;
int inf=-1;
ll mod = pow(10, 9) + 7;
 
int main(){
    int n;double a;
    double sum=0.0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        sum+=1/a;
    }
    cout<<fixed<<setprecision(6)<<1/sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define repd(i, n) for (ll i = (n)-1; i >= 0; --i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int a, p;
    cin >> a >> p;
    cout << (3 * a + p) / 2 << endl;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  long long H;
  cin >> H;
  
  //攻撃回数//
  long long num = 0LL;
  
  //モンスターの個数//
  long long num2 = 1LL;
  
  //モンスターの体力//
  long long num3 = H;
  
  while(true){
    if(num3 > 1LL){
      num = num + num2;
      num2 = num2 * 2;
      num3 = num3 / 2;
    }
    else{
      num = num + num2;
      break;
    }
  }
  
  cout << num << endl;
  
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct BipartiteMatching {
	int n;
	vector<vector<int>> g;
	vector<int> match;
	vector<int> used;
	BipartiteMatching(int n) : n(n), g(n), match(n), used(n) {}
	void addEdge(int u, int v) {
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	int maximumMatching() {
		int cnt = 0;
		fill(match.begin(), match.end(), -1);
		for (int v = 0; v < n; v++) {
			if (match[v] == -1) {
				fill(used.begin(), used.end(), false);
				if (augment(v)) cnt++;
			}
		}
		return cnt;
	}
	bool augment(int v) {
		used[v] = true;
		for (int u : g[v]) {
			int w = match[u];
			if (w == -1 || (!used[w] && augment(w))) {
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N, M; cin >> N >> M&&N;) {
		using Edge = tuple<double, int, int>;
		vector<Edge> es;
		vector<int> x(N), y(N), v(N); rep(i, 0, N) {
			cin >> x[i] >> y[i] >> v[i];
		}
		vector<int> bx(M), by(M); rep(i, 0, M) {
			cin >> bx[i] >> by[i];
		}
		rep(i, 0, N)rep(j, 0, M) {
			double d = sqrt((x[i] - bx[j])*(x[i] - bx[j]) + (y[i] - by[j])*(y[i] - by[j])) / v[i];
			es.emplace_back(d, i, j);
		}
		sort(all(es));

		auto f = [&](int x) {
			BipartiteMatching bm(N + M);
			rep(i, 0, x + 1) {
				double d; int a, b; tie(d, a, b) = es[i];
				bm.addEdge(a, N + b);
			}
			return bm.maximumMatching() == M;
		};
		auto binarySearch = [&](int ng, int ok) {
			if (f(ng))return ng;
			while (ng + 1 < ok) {
				int m = (ng + ok) / 2;
				if (f(m))
					ok = m;
				else
					ng = m;
			}
			return ok;
		};

		int ok = binarySearch(0, es.size() - 1);
		cout << fixed << setprecision(10);
		cout << get<0>(es[ok]) << endl;
	}
	return 0;
}

Measured memory_bytes: 3540
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		
		int ans = a;
		
		if (a==b) {
			ans=c;
		}else if (a==c) {
			ans=b;
		}
		
		System.out.println(ans);
		
		scanner.close();
	}

}


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


int main(){
  long n,h,thsum = 0;
  cin >> n >> h;
  vector<long> a(n),b(n);
  for(int i = 0;i < n;i++){
    cin >> a.at(i) >> b.at(i);
    thsum += b.at(i);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  auto iter = lower_bound(b.begin(),b.end(),a.at(n-1));
  long kekka;
  if(iter == b.end()){
    while(h > 0){
      h -= a.at(n-1);
      kekka++;
    }
  }
  else if(iter != b.end()){
    for(int i = n-1;i >= iter-b.begin();i--){
      h -= b.at(i);
      kekka++;
      if(h <= 0){
        break;
      }
    }
    while(h > 0){
      h -= a.at(n-1);
      kekka++;
    }
  }
  cout << kekka << endl;
}

Measured memory_bytes: 1792
n=int(input())
l=list(map(int,input().split()))
flg=True
counter=0
while flg:
    flg=False
    for j in reversed(range(1,n)):
        if l[j]<l[j-1]:
            l[j],l[j-1]=l[j-1],l[j]
            flg=True
            counter+=1
for i in range(n):
    if i!=n-1:
        print(l[i],end=' ')
    else:
        print(l[i])
print(counter)


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

using namespace std;
const int IINF = INT_MAX;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000000000
int main(){
    ll w,h,x,y;
	cin >> w >> h >> x >> y;
	
	double w1 = w;
	double h1 = h;
	cout << fixed << setprecision(9) <<  (w1*h1)/2 << " ";
	
	if(2*y == h && 2*x == w){
		 cout << 1 << endl;
	}else{
		 cout << 0 << endl;
	}
    return 0;	
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int a,b,x;cin>>x>>a>>b;
  string ans="dangerous";
  if((a-b)>=0)ans="delicious";
  else if((b-a)<=x)ans="safe";
  cout(ans);
  
  return 0;
}

Measured memory_bytes: 125568
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define in insert
#define REP(i,n) for (int i = 1; i <= n; i++)
#define matrix vector<vector<ll> > 
using namespace std;
 
const ll N = 1e5+2;
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll LOG = 25;
 
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
vll adj[N];
ll ans[N];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	// ifstream fin ("sound.in");
	// ofstream fout("sound.out");
	
	
	ll n;
	cin >> n;
	for(int i =2;i<=n;i++){
		ll u,v;
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}for(int i =1;i<=n;i++)ans[i]=-INF;
	ll k;
	cin >> k;
	priority_queue<pll,vector<pll>,greater<pll>> pq;
	for(int i =1;i<=k;i++){
		ll nd,val;cin>>nd>>val;
		ans[nd] = val;
		pq.push(mp(val,nd));
	}

	while(!pq.empty()){
		pll p = pq.top();
		pq.pop();
		ll u = p.s;
		ll val = p.f;
		for(auto v:adj[u]){
			if(ans[v] == -INF){
				ans[v] = ans[u] + 1;
				pq.push({ans[v],v});
			}
			else{
				if(abs(ans[v] - ans[u]) != 1){
					cout<<"No\n";
					return 0;
				}
			}
		}
	}
	cout<<"Yes\n";
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 9460
// abc129d.cpp : Lamp
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);i++)

int main(){
	int h,w; cin>>h>>w;

	vector<string> s(h);
	vector<vi> c(h,vi(w));

	rp(i,h) cin>>s[i];

	rp(t,h){ //LR
		int x = 0, y = 0;
		rp(l,w){
			c[t][l] += s[t][l]=='.'? x++: x=0; //L
			int r = w - 1 - l;
			c[t][r] += s[t][r]=='.'? y++: y=0; //R
		}
	}

	rp(l,w){ //TB
		int x = 0, y = 0;
		rp(t,h){
			c[t][l] += s[t][l]=='.'? x++: x=0; //T
			int b = h - 1 - t;
			c[b][l] += s[b][l]=='.'? y++: y=0; //B
		}
	}

	int ans = 1;
	rp(i,h)
		rp(j,w)
			if(ans < c[i][j]+1) ans = c[i][j] + 1;

	cout<< ans <<endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
int main() {
    int h,w;
    cin>>h>>w;
    char s[h+1][w+1];
    rep(i,h){
        rep(j,w){
            cin>>s[i+1][j+1];
        }
    }
    int dp[h+1][w+1];
    if (s[1][1]=='#'){
        dp[1][1]=1;
    }
    else{
        dp[1][1]=0;
    }
    for (int i=2;i<w+1;i++){
        if (s[1][i]!='#'){
            dp[1][i]=dp[1][i-1];
        }
        else{
            if (s[1][i-1]=='#'){
                dp[1][i]=dp[1][i-1];
            }
            else{
                dp[1][i]=dp[1][i-1]+1;
            }
        }
    }
    for (int i=2 ;i<h+1;i++){
        if (s[i][1]!='#'){
            dp[i][1]=dp[i-1][1];
        }
        else{
            if(s[i-1][1]=='#'){
                dp[i][1]=dp[i-1][1];
            }
            else{
                dp[i][1]=dp[i-1][1]+1;
            }
        }
    }
    for (int i=2;i<h+1;i++){
        for (int j=2;j<w+1;j++){
            if (s[i][j]!='#'){
                dp[i][j]=min(dp[i-1][j],dp[i][j-1]);
            }
            else{
                int b1=0,b2=0;
                if (s[i-1][j]!='#'){
                    b1=1;
                }
                if (s[i][j-1]!='#'){
                    b2=1;
                }
                dp[i][j]=min(dp[i-1][j]+b1,dp[i][j-1]+b2);
            }
          //cout<<dp[i][j]<<" "<<i<<" "<<j<<endl;
        }
    }
    cout<<dp[h][w]<<endl;


    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	
	int a,b,k;
	char op;
	
	while(1){
		scanf("%d %c %d", &a,&op,&b);
		if(op == '?'){
			break;
		}
		else if(op == '+'){
			k = a + b;
				printf("%d\n",k);
		}
		else if(op == '-'){
			k = a-b;
				printf("%d\n",k);
		}
		else if(op == '*'){
			k = a*b;
				printf("%d\n",k);
		}
		else if(op == '/'){
			k = a/b;
				printf("%d\n",k);
		}
		else{
			k = a%b;
				printf("%d\n",k);
		}
	}
	return 0;
}

Measured memory_bytes: 600
import sys
import os

def file_input():
    f = open('/input.txt', 'r')
    sys.stdin = f

def main():
    # file_input()
    N=input()
    T=input()

    if len(N)+1==len(T) and N==T[:-1]:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  string s;
  cin >> s;

  ll n = s.size();

  vvll dp(n + 1, vll(2));

  dp[0][0] = s[n - 1] - '0';
  dp[0][1] = 1 + 10 - dp[0][0];

  REP(i, n) {
    ll v = s[n - 1 - i] - '0';

    dp[i][0] = v + min(dp[i - 1][0], dp[i - 1][1]);
    if (v == 9) {
      dp[i][1] = min(11 - v + dp[i - 1][0], dp[i - 1][1]);
    } else {
      dp[i][1] = 11 - v + min(dp[i - 1][0], dp[i - 1][1]);
      chmin(dp[i][1], 9 - v + dp[i - 1][1]);
    }
  }

  cout << min(dp[n - 1][0], dp[n - 1][1]) << endl;

  return 0;
}


Measured memory_bytes: 55964
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;

	private static long loopSize = 0;
	private static long loopBegin = -1;
	private static long loopEnd = 0;
	private static long[] sorted;
	public class Node
	{
		public int Index{get;set;}
		public int Next{get;set;}
		public List<int> Prev {get;set;}
		public bool Visited{get;set;}
		public long Deep{get;set;}
		
	}
	public static void Main(string[] args)
	{
		var p = Input();
		var n = p[0].ToInt();
		var k = p[1].ToLong();
		var nodes = new Node[n];
		for(int i = 0; i < n; i++)
		{
			nodes[i] = new Node(){Index = i, Next = -1, Prev = new List<int>(), Deep = -1};
		}
		
		var q = Input().ToInt(-1);
		for(int i = 0; i < n; i++)
		{
			nodes[i].Next =q[i];
			nodes[q[i]].Prev.Add(i);
		}
		
		sorted = new long[n];
		for(int i = 0; i < n; i++)
			sorted[i]=-1;
		DFS(0, 0, nodes, -1);
		
		/*
		Console.WriteLine("{0} {1} {2}", loopSize, loopBegin, loopEnd);
		for(int i = 0; i< n; i++)
		{
			Console.WriteLine("{0}:{1}", i, sorted[i]);
		}
		*/
		if(loopBegin == loopEnd)
		{
			if(k < loopBegin)
			{
				Console.WriteLine(sorted[k]+1);
			}
			else
			{
				Console.WriteLine(sorted[loopEnd]+1);
			}
			return;
		}
		
		if(loopBegin == -1)
		{
			Console.WriteLine(sorted[(int)k]+1);
			return;
		}
		if(k < loopBegin)
		{
			Console.WriteLine(sorted[(int)k]+1);
		}
		else
		{
			//Console.WriteLine("Ptr:{0} / raw:", loopBegin + ((k-loopBegin) % loopSize));
			//, sorted[loopBegin + ((k-loopBegin) % loopSize)]);
			Console.WriteLine(sorted[(int)(loopBegin + ((k-loopBegin) % loopSize))]+1);
		}
	}
	
	static void DFS(long index, long deep, Node[] nodes, long prev)
	{
		if(index >= nodes.Length)
			return;
		if(nodes[(int)index].Visited)
		{
			loopSize = nodes[(int)prev].Deep - nodes[(int)index].Deep + 1;
			loopEnd = prev;
			loopBegin = nodes[(int)index].Deep ;
			if(deep < nodes.Length)
				sorted[(int)deep] = index;
			/*if(loopSize == 1)
				loopBegin--;
				*/
			return;
		}
		nodes[(int)index].Visited = true;
		nodes[(int)index].Deep = deep;
		sorted[(int)deep] = index;

		DFS(nodes[(int)index].Next, deep+1, nodes, index);
	}
	
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 88108
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mk make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
#include <bits/stdc++.h>
using namespace std;
int main(){
    double a,b,c,d;
    std::cin >> a>>b>>c>>d;
    std::cout <<keta(10)<< sqrt(pow(c-a,2)+pow(d-b,2)) << std::endl;
}


Measured memory_bytes: 3244
#include<iostream>
#include<algorithm>
#define MAX 200000
using namespace std;
int main(){
    int store[MAX],n;
    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> store[i];
    }
    int maxv = -2000000000,minv = store[0];
    for(int i = 1; i < n; i ++){
        maxv = max(maxv , store[i] - minv);
        minv = min(minv , store[i]);
    }
    cout << maxv << endl;
}



Measured memory_bytes: 3872
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <map>
#include<set>
#include <vector>
#include <string>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
const int mod=1e9+7;

int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	int min;
	if(a*n<b)
		min=a*n;
	else
		min=b;
	cout<<min<<endl;


 	 return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//想定解答との絶対誤差または相対誤差が 10−6以下の場合+1以上だしておく。適当に15とかでもおｋ．
//cout << fixed << setprecision(15);

int main() {
    string s;
    ll K;
    map<char, int> mp;
    mp['a'] = 0;
    mp['b'] = 25;
    mp['c'] = 24;
    mp['d'] = 23;
    mp['e'] = 22;
    mp['f'] = 21;
    mp['g'] = 20;
    mp['h'] = 19;
    mp['i'] = 18;
    mp['j'] = 17;
    mp['k'] = 16;
    mp['l'] = 15;
    mp['m'] = 14;
    mp['n'] = 13;
    mp['o'] = 12;
    mp['p'] = 11;
    mp['q'] = 10;
    mp['r'] = 9;
    mp['s'] = 8;
    mp['t'] = 7;
    mp['u'] = 6;
    mp['v'] = 5;
    mp['w'] = 4;
    mp['x'] = 3;
    mp['y'] = 2;
    mp['z'] = 1;
    cin >> s >> K;
    rep(i, 0, s.length()) {
        if (K >= mp[s[i]]) {
            K -= mp[s[i]];
            s[i] = 'a';
        }
    }


    while(K>0) {
        if (K > 26) {
            if (s[s.length()-1] == 'a') {
                K -= 26;
            } else {
                K--;
                if (s[s.length()-1] == 'z') {
                    s[s.length()-1] = 'a';
                } else {
                    s[s.length()-1] += 1;
                }
            }
        } else {
            K--;
            if (s[s.length()-1] == 'z') {
                s[s.length()-1] = 'a';
            } else {
                s[s.length()-1] += 1;
            }
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define li long int
#define ld long double
#define pl pair<long long, long long>
#define pi pair<int, int>
#define ppl pair<pl, ll>
#define ppi pair<int, pi>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LLFOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define MOD 1000000007
#define M2 998244353
//std::cout <<setprecision(30) << av << endl;
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--){
        ll a, b, n;
        cin >> a >> b >> n;
        //(an)/b

        cout << (min(b-1, n)*a)/b << endl;
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int w, a, b;
    cin >> w >> a >> b;
    if (a + w < b) cout << b - a - w;
    else if (b + w < a) cout << a - b - w;
    else cout << 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int p=1e9+7,N=2e5+5,NN=N+5;
ll fac[NN],inv[NN];
inline ll modpow(ll a,ll x)
{
	ll res=1;
	for(;x;x>>=1,a=a*a%p)
		if(x&1)	res=res*a%p;
	return res;
}
inline ll finv(ll x)
{
	return modpow(x,p-2);
}
inline ll c(ll n,ll m)
{
	return fac[n]*inv[n-m]%p*inv[m]%p;
}
inline ll calc(ll stx,ll sty,ll edx,ll edy)
{
	return c(edy-sty+edx-stx,edx-stx);
}
int main()
{
	ll n=ri(),m=ri(),a=ri(),b=ri(),i,ans;
	for(inv[0]=fac[0]=1,i=1;i<=N;i++)
	{
		fac[i]=fac[i-1]*i%p;
	//	inv[i]=finv(fac[i]);
	}
	inv[N]=finv(fac[N]);
	for(i=N-1;i>=1;i--)	inv[i]=inv[i+1]*(i+1)%p;
	ans=calc(1,1,n,m);
//	wi(ans);putchar('\n');
	for(i=1;i<=b;i++)
	{
		ans=(ans-calc(1,1,n-a+1-1,i)*calc(n-a+1,i,n,m)%p)%p;
	//	printf("%lld %lld %lld %lld\n",n-a+1,i,calc(1,1,n-a+1,i),calc(n-a+1,i,n,m));
	}
	wi((ans%p+p)%p);
	return 0;
}
/*
10 7 3 4

2 3 1 1

4 3 2 2

3570
2
6
*/


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

void input(vector<int>& rvnSeq)
{
  int nSeqSiz;
  cin >> nSeqSiz;
  rvnSeq.resize(nSeqSiz);

  for (int& rnSeq : rvnSeq)
    cin >> rnSeq;
}
  
void calcSeqMaxNum(const vector<int>& cnrvnSeq)
{
  vector<int> vnSrtSeq(cnrvnSeq);
  sort(begin(vnSrtSeq), end(vnSrtSeq));

  for (int i = 0; i < cnrvnSeq.size(); i++)
  {
    int nMax = vnSrtSeq[vnSrtSeq.size() - 1];
    if (cnrvnSeq[i] == vnSrtSeq[vnSrtSeq.size() - 1])
      nMax = vnSrtSeq[vnSrtSeq.size() - 2];

    cout << nMax << endl;
  }
}
  
int main()
{
  vector<int> vnSeq;

  input(vnSeq);
  calcSeqMaxNum(vnSeq);

  return 0;
}

Measured memory_bytes: 4840
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int w = sc.nextInt();
			final int h = sc.nextInt();
			
			if(h == 0 && w == 0){
				break;
			}
			
			int cur_x = 1;
			int cur_y = 1;
			int move = 0;
			
			while(true){
				String str = sc.next();
				
				if("STOP".equals(str)){
					break;
				}else if("FORWARD".equals(str)){
					int m = sc.nextInt();
					
					switch(move){
					case 0:
						cur_y = cur_y + m > h ? h : cur_y + m;
						break;
					case 1:
						cur_x = cur_x + m > w ? w : cur_x + m;
						break;
					case 2:
						cur_y = cur_y - m < 1 ? 1 : cur_y - m;
						break;
					case 3:
						cur_x = cur_x - m < 1 ? 1 : cur_x - m;
						break;
					}
				}else if("BACKWARD".equals(str)){
					int m = sc.nextInt();
					
					switch(move){
					case 0:
						cur_y = cur_y - m < 1 ? 1 : cur_y - m; 
						break;
					case 1:
						cur_x = cur_x - m < 1 ? 1 : cur_x - m;
						break;
					case 2:
						cur_y = cur_y + m > h ? h : cur_y + m;
						break;
					case 3:
						cur_x = cur_x + m > w ? w : cur_x + m;
						break;
					}
				}else if("RIGHT".equals(str)){
					move = move >= 3 ? 0 : move + 1;
				}else if("LEFT".equals(str)){
					move = move <= 0 ? 3 : move - 1;
				}
			}
			
			System.out.println(cur_x + " " + cur_y);
		}
		
	}

}

Measured memory_bytes: 12000
#include <stdio.h>
#include <algorithm>
#include <cmath>

using namespace std;

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

  float diff = 10000000;
  int result = 1;
  int h[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", h+i);
    float avg = t - h[i] * 0.006;
    
    if (abs(avg - a) < diff) {
      diff = abs(avg - a);
      result = i+1;
    }
  }

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

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <string>
#include <cstdio>

using namespace std;

int main()
{

    int n;
    cin >> n;
    vector<int> sequence(n);

    int i = 0;
    do
        cin >> sequence[i];
    while (++i < n);

    //method 1: use STL algorithm
    // reverse(sequence.begin(), sequence.end());
    // i = 0;
    // do
    // {
    //     if (i)
    //         cout << ' ';
    //     cout << sequence[i];        
    // }
    // while (++i < n);
    // cout << endl;


    //directly output the vector from the end to the beginning
    while (n--)
    {
        //method 1
        // cout << sequence[n];
        // if (n)
        //     cout << ' ';

        //method 2
        // cout << sequence[n] << (n? " ": "");

        //method 3
        // cout << sequence[n] << (n? " ": begin({'\0'}));

        //method 4
        printf("%d%s", sequence[n], (n? " ": ""));
    }
    cout << endl;

}


Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  string S;
  cin >> S;

  int ans=1000;
  for(int i=0;i<S.size()-2;i++){
    int x = (S.at(i)-'0')*100 +(S.at(i+1)-'0')*10 +(S.at(i+2)-'0');
    int a=abs(753-x);
    if(a<ans) ans=a;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int m[100];
  int f[100];
  int r[100];
  while(true)
    {
      int i=0;
      cin>>m[i]>>f[i]>>r[i];
      if(m[i]==-1 && f[i]==-1 && r[i]==-1)break;
      int sum[100];
      sum[i]=m[i]+f[i];
      if(m[i]==-1 || f[i]==-1 ||sum[i]<30)
	{
	  cout<<"F"<<endl;
	}else{
	if(sum[i]>=80)
	  {
	    cout<<"A"<<endl;
	  }
	if(65<=sum[i] && sum[i]<80)
	  {
	    cout<<"B"<<endl;
	  }
	if(50<=sum[i] && sum[i]<65)
	  {
	    cout<<"C"<<endl;
	  }
	if(30<=sum[i] && sum[i]<50)
	  {
	    if(r[i]>=50)
	      {
		cout<<"C"<<endl;
	      }else{
	      cout<<"D"<<endl;
	    }
	  }
      }
    }
  return 0;
}



Measured memory_bytes: 3004
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

vector<int> par;

void Initpar(int n){
  par = vector<int>(n); 
  for(int i=0; i<n; i++) par.at(i) = i;
}

int root(int x){
  if(x == par.at(x)) return x;
  else return par.at(x) = root(par.at(x));
}

void unite(int x, int y){
  int rx = root(x);
  int ry = root(y);
  if(rx == ry) return ;
  if(rx < ry) par.at(ry) = rx;
  else par.at(rx) = ry;
}

bool same(int x, int y){
  return root(x) == root(y);
}

void update_par(){
  for(int i=0;i<par.size();i++){
    root(i);
  }
}

int main(){
  int n,m;
  cin >> n >> m;
  Initpar(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;b--;
    unite(a,b);
  }
  update_par();
  vi cnt(n,0);
  rep(i,n){
    cnt.at(par.at(i))++;
  }
  int maxi = 0;
  rep(i,n){
    maxi = max(maxi, cnt.at(i));
  }
  cout << maxi << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n,m;cin>>n>>m;
	vii c,d;
	vector<vector<bool>>a(n,vector<bool>(m));
	int cnt=0;
	rep(i,n){
		rep(j,m){
			int x;cin>>x;
			if(x%2){
				a[i][j]=false;
				cnt++;
			}
			else a[i][j]=true;
		}
	}
	bool b=true;
	rep(i,n){
		if(i%2==0){
			rep(j,m){
				if(!a[i][j]&&b){
					cnt--;
					if(cnt>0){
						b=false;
						c.PB(MP(i,j));
						if(j==m-1&&i<n-1){
							d.PB(MP(i+1,j));
						}
						else if(j<m-1)d.PB(MP(i,j+1));
						continue;
					}
				}
				else if(a[i][j]&&!b){
					c.PB(MP(i,j));
					if(j==m-1&&i<n-1){
						d.PB(MP(i+1,j));
					}
					else if(j<m-1)d.PB(MP(i,j+1));
					continue;
				}
				else if(!a[i][j]&&!b){
					cnt--;
					b=true;
					continue;
				}
			}
		}
		else{
			for(int j=m-1;j>=0;--j){
				if(!a[i][j]&&b){
					cnt--;
					if(cnt>0){
						b=false;
						c.PB(MP(i,j));
						if(j==0&&i<n-1){
							d.PB(MP(i+1,j));
						}
						else if(j>0) d.PB(MP(i,j-1));
						continue;
					}
				}
				else if(a[i][j]&&!b){
					c.PB(MP(i,j));
					if(j==0&&i<n-1){
						d.PB(MP(i+1,j));
					}
					else if(j>0)d.PB(MP(i,j-1));
					continue;
				}
				else if(!a[i][j]&&!b){
					cnt--;
					b=true;
					continue;
				}
			}
		}
	}
	cout<<c.size()<<endl;
	rep(i,c.size()){
		cout<<c[i].F+1<<" "<<c[i].S+1<<" "<<d[i].F+1<<" "<<d[i].S+1<<endl;
	}
}


Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { 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 long long INF = 2LL << 60;
using ll = long long;
using P = pair<string, ll>;

int main(int argc, char const *argv[]) {
    ll n, h[3][100100], dp[3][100100];
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin >> h[j][i];
            dp[j][i]=0;
        }
    }
    dp[0][0]=h[0][0];
    dp[1][0]=h[1][0];
    dp[2][0]=h[2][0];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k) continue;
                chmax(dp[j][i],dp[k][i-1]+h[j][i]);
            }
        }
    }
    cout << max(max(dp[0][n-1],dp[1][n-1]),dp[2][n-1]) << endl;

    return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		int price = 0;
		price += Math.min(2*C, A+B) * Math.min(X, Y);
		if(X>Y) {
			price += (X-Y)*A;
		}else {
			price += (Y-X)*B;
		}

		int AB = Math.max(X, Y)*2*C;

		System.out.println(Math.min(price, AB));

	}

}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

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

    int n = sc.nextInt();

    int[] d = new int[n];
    for (int i = 0; i < n; i++) {
      d[i] = sc.nextInt();
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        if (i != j) {
          ans += d[i] * d[j];
        }
      }
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 22228
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include <numeric>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << #s << " " << s << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void printVector(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int N, K;
    cin >> N >> K;

    vector<ll> H;
    H.reserve(N);

    FOR(i, 0, N){
        ll val;
        cin >> val;
        H.push_back(val);
    }

    sort(ALL(H));

    ll minDiff = 10000000000;
    FOR(i, 0, N-K+1){
        ll low = H[i];
        ll high = H[i+K-1];
        ll diff = high - low;

        if(diff < minDiff){
            minDiff = diff;
        }
    }

    p(minDiff);

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
  
int main()
{
    int a, b;
      
    cin >> a >> b;
      
    if ( a < b ) cout << "a < b" << endl;
    else if ( a > b ) cout << "a > b" << endl;
    else cout << "a == b" << endl;
  
    return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int n,x;
int odd,even,fr;
int main(){
	cin>>n;
	while(n--){
		cin>>x;
		if(x%4==0) fr++;
		else if(x%2==0) even++;
		else odd++;
	}
	string ans;
	if(even==0){
		if(odd<=fr+1) ans="Yes";
		else ans="No";
	}else{
		if(odd<=fr)ans="Yes";
		else ans="No";
	}
	cout<<ans;
	return 0;
}

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

int main()
{
	auto& in = cin;

	const int numA = 26;
	int D;
	in >> D;
	vector<int> cs;
	vector<vector<int>> ss;
	for (int i = 0; i < numA; ++i) {
		int c;
		in >> c;
		cs.push_back(c);
	}
	for (int i = 0; i < D; ++i) {
		vector<int> s;
		for (int j = 0; j < numA; ++j) {
			int is;
			in >> is;
			s.push_back(is);
		}
		ss.emplace_back(move(s));
	}

	int sat = 0;
	vector<int> ds(numA);
	vector<int> ts;
	for (int i = 0; i < D; ++i) {
		int t;
		in >> t; --t;
		ts.push_back(t);
		sat += ss[i][t];
		for (int j = 0; j < numA; ++j)
			++ds[j];
		ds[t] = 0;
		for (int j = 0; j < numA; ++j)
			sat -= cs[j] * ds[j];
		//cout << sat << "\n";
	}

	int M;
	in >> M;
	for (int i = 0; i < M; ++i) {
		int d, newT;
		in >> d >> newT; --d; --newT;
		int prevT = ts[d];
		int prevTdaysBefore = distance(ts.rbegin() + (D - d), find(ts.rbegin() + (D - d), ts.rend(), prevT));
		int prevTdaysAfter = distance(ts.begin() + d, find(ts.begin() + d + 1, ts.end(), prevT));
		int newTdaysBefore = distance(ts.rbegin() + (D - d), find(ts.rbegin() + (D - d), ts.rend(), newT));
		int newTdaysAfter = distance(ts.begin() + d, find(ts.begin() + d + 1, ts.end(), newT));
		sat -= cs[prevT] * (prevTdaysBefore + 1) * prevTdaysAfter;
		sat += cs[newT] * (newTdaysBefore + 1) * newTdaysAfter;
		sat -= ss[d][prevT];
		sat += ss[d][newT];
		ts[d] = newT;
		cout << sat << "\n";
	}

	return 0;
}


Measured memory_bytes: 3640