akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define forn(i, a, b) for (int i = a; i < b; i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int, int> s
#define lpair pair<LL, LL>
#define MAXN 100004

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

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  char str[100]={};
  long long k=0;
  int i = 0;
  
  scanf("%s",str);
  scanf("%lld",&k);
  for(i=0;i<100 && i<k;i++){
    if(str[i] != '1'){
      printf("%c",str[i]);
      return 0;
    }
  }
  printf("1");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N;cin>>N;
	bool ans = false;
	rep(i,N){
		int t; cin>>t;
		if(t%2 == 1)ans = true;
	}
	cout<<((ans)?"first":"second")<<endl;
	return 0;
}

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

using std::cin;
using std::cout;



int main(int argc, char* argv[])
{
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N, K;
  cin >> N >> K;

  cout << (((N+1)/2) >= K ? "YES\n" : "NO\n");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  const double pi = acos(-1);
  // double theta = max(h * 30, m * 6) - min(h * 30, m * 6);

  double theta = h * 30 + m * 0.5 - m * 6;

  theta = theta >= 180 ? 360 - theta : theta;

  // cout << theta << endl;

  theta = (theta / 180) * pi;
  // cout << theta << endl;

  double ans = a * a + b * b - 2 * a * b * cos(theta);

  printf("%.17lf\n", sqrt(ans));
}

Measured memory_bytes: 4104
N = int(input())

V = list(map(int,input().split()))
C = list(map(int,input().split()))

import copy

flag = [0]*N
def dfs(x, y):
    if y==1:
        flag[x] = 1
    else:
        flag[x] = 0
    if x==N-1:
        value = 0
        cost = 0
        for i in range(N):
            if flag[i] == 1:
                value += V[i]
                cost += C[i]
        # print(flag)
        # for i in range(N):
        #     flag[i] = 0
        return value - cost

    
    return max(dfs(x+1, 0),dfs(x+1, 1))

print(dfs(-1,0))


Measured memory_bytes: 49880
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
char str[600][600];
int r[30][2];
int c[30][2];
vector<int>w[30];
map<int,int>m;
int solve(int a){
	if(m.count(a))return m[a];
	int ret=__builtin_popcount(a);
	for(int i=0;i<26;i++)if(a&(1<<i)){
		for(int j=0;j<w[i].size();j++){
			if(!(a&w[i][j])){
				ret=min(ret,solve(a-(1<<i)));
			}
		}
	}
	return m[a]=ret;
}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",str[i]);
	for(int i=0;i<26;i++)r[i][0]=r[i][1]=-1;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		if(str[i][j]!='.'){
			if(!~r[str[i][j]-'A'][0]){
				r[str[i][j]-'A'][0]=i;
				c[str[i][j]-'A'][0]=j;
			}else{
				r[str[i][j]-'A'][1]=i;
				c[str[i][j]-'A'][1]=j;
			}
		}
	}
	for(int i=0;i<26;i++){
		if(!~r[i][0])continue;
		if(r[i][0]==r[i][1]){
			if(c[i][0]+1<c[i][1]){
				int key=0;
				for(int j=0;j<26;j++){
					if(r[i][0]==r[j][0]&&c[i][0]<c[j][0]&&c[j][0]<c[i][1])key|=(1<<j);
					if(r[i][0]==r[j][1]&&c[i][0]<c[j][1]&&c[j][1]<c[i][1])key|=(1<<j);
				}
				w[i].push_back(key);
			}
		}else if(c[i][0]==c[i][1]){
			if(r[i][0]+1<r[i][1]){
				int key=0;
				for(int j=0;j<26;j++){
					if(c[i][0]==c[j][0]&&r[i][0]<r[j][0]&&r[j][0]<r[i][1])key|=(1<<j);
					if(c[i][0]==c[j][1]&&r[i][0]<r[j][1]&&r[j][1]<r[i][1])key|=(1<<j);
				}
				w[i].push_back(key);
			}
		}else{
			int key=0;
			for(int j=0;j<26;j++){
				if(i==j)continue;
				if(r[i][0]==r[j][0]&&min(c[i][0],c[i][1])<=c[j][0]&&c[j][0]<=max(c[i][0],c[i][1]))key|=(1<<j);
				if(c[i][1]==c[j][0]&&r[i][0]<=r[j][0]&&r[j][0]<=r[i][1])key|=(1<<j);
				if(r[i][0]==r[j][1]&&min(c[i][0],c[i][1])<=c[j][1]&&c[j][1]<=max(c[i][0],c[i][1]))key|=(1<<j);
				if(c[i][1]==c[j][1]&&r[i][0]<=r[j][1]&&r[j][1]<=r[i][1])key|=(1<<j);
			}
			w[i].push_back(key);
			key=0;
			for(int j=0;j<26;j++){
				if(i==j)continue;
				if(r[i][1]==r[j][0]&&min(c[i][0],c[i][1])<=c[j][0]&&c[j][0]<=max(c[i][0],c[i][1]))key|=(1<<j);
				if(c[i][0]==c[j][0]&&r[i][0]<=r[j][0]&&r[j][0]<=r[i][1])key|=(1<<j);
				if(r[i][1]==r[j][1]&&min(c[i][0],c[i][1])<=c[j][1]&&c[j][1]<=max(c[i][0],c[i][1]))key|=(1<<j);
				if(c[i][0]==c[j][1]&&r[i][0]<=r[j][1]&&r[j][1]<=r[i][1])key|=(1<<j);
			}
			w[i].push_back(key);
		}
	}
	int st=0;
	int ret=0;
	for(int i=0;i<26;i++){
		if(!~r[i][0])continue;
		ret++;
		bool ok=false;
		for(int j=0;j<w[i].size();j++)if(!w[i][j])ok=true;
		if(!ok)st+=(1<<i);
	}
	printf("%d\n",ret*2-solve(st)*2);
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,cnt = 0,ans = INF;
	string s;
	cin >> n >> s;
	for(int i = 0;i < n;i++){
		if(s[i] == '.') cnt++;
	}
	ans = cnt;
	for(int i = 0;i < n;i++){
		if(s[i] == '#') cnt++;
		else cnt--;
		chmin(ans,cnt);
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

		for (int i = 0; i < 4; i++) {
			a = Math.min(a, sc.nextDouble());
		}

		double ans = 4 + Math.ceil(n/a);
		System.out.println((long)ans);
		sc.close();
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

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

  vector<bool> visited(k, false);
  typedef pair<int, int> pi;
  priority_queue<pi, vector<pi>, greater<pi> > que;

  int ans = 0;
  que.push(make_pair(0, 1));
  while (!que.empty()) {
    int cost = que.top().first;
	int mod = que.top().second;
	que.pop();

	if (visited[mod]) continue;
	visited[mod] = true;

	if (mod == 0) {
	  ans = cost + 1;
	  break;
	}

	que.push(make_pair(cost, (mod * 10) % k));
	que.push(make_pair(cost + 1, (mod + 1) % k));
  }

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


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int x[100];
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    int sum=100000000;
    int min=0;
    for(int i=1;i<100;i++){
        int tmpsum=0;
        for(int k=0;k<n;k++){
            tmpsum+=(i-x[k])*(i-x[k]);
        }
        if(sum>tmpsum){
            min=i;
            sum=tmpsum;
        }
    }
    cout<<sum;
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a * b % 2 == 1){
    cout << "Odd" << endl;
  } else if (a * b % 2 == 0){
    cout << "Even" << endl;
  }
}

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

int main()
{
    string S;
    cin >> S;
    size_t n0 = 0;
    for(auto& c : S){
        if(c=='0') n0++;
    }
    cout<<2*min(n0, S.size()-n0)<<endl;

    return 0;
}

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

int dice[6],kari[6],sum,n;
string str;

int main(){
	while(1){
		sum=0;
		for(int i=0;i<6;i++){dice[i]=i+1;kari[i]=dice[i];}
		sum+=dice[0];
		cin>>n;
		if(n==0){break;}
		for(int i=0;i<n;i++){
			cin>>str;
			if(str=="North"){
				dice[4]=kari[0];
				dice[5]=kari[4];
				dice[1]=kari[5];
				dice[0]=kari[1];
			}
			else if(str=="East"){
				dice[2]=kari[0];
				dice[5]=kari[2];
				dice[3]=kari[5];
				dice[0]=kari[3];
			}
			else if(str=="West"){
				dice[3]=kari[0];
				dice[5]=kari[3];
				dice[2]=kari[5];
				dice[0]=kari[2];
			}
			else if(str=="South"){
				dice[1]=kari[0];
				dice[5]=kari[1];
				dice[4]=kari[5];
				dice[0]=kari[4];
			}
			else if(str=="Right"){
				dice[1]=kari[2];
				dice[3]=kari[1];
				dice[4]=kari[3];
				dice[2]=kari[4];
			}
			else if(str=="Left"){
				dice[2]=kari[1];
				dice[4]=kari[2];
				dice[3]=kari[4];
				dice[1]=kari[3];
			}
			for(int i=0;i<6;i++){kari[i]=dice[i];}
			sum+=dice[0];
		}
		cout<<sum<<endl;

	}
	
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[5][4][11];
    for (int i=1;i<=4;i++){
        for(int j=1;j<=3;j++){           
            for (int k=1;k<=10;k++){
                a[i][j][k]=0;
            }
        }
    }
    for (int i=0;i<n;i++){
        int b,f,r,v;
        cin>>b>>f>>r>>v;
        a[b][f][r]+=v;
        if (a[b][f][r]<0){
            a[b][f][r]=0;
        }
        else if(a[b][f][r]>9){
            a[b][f][r]=9;
        }
    }
    for (int i=1;i<=3;i++){
        for (int j=1;j<=10;j++){
            cout<<" "<<a[1][i][j];
        }
        cout<<endl;
    }
    cout<<"####################"<<endl;
    
    for (int i=1;i<=3;i++){
        for (int j=1;j<=10;j++){
            cout<<" "<<a[2][i][j];
        }
        cout<<endl;
    }
    cout<<"####################"<<endl;
    
    for (int i=1;i<=3;i++){
        for (int j=1;j<=10;j++){
            cout<<" "<<a[3][i][j];
        }
        cout<<endl;
    }
    cout<<"####################"<<endl;
    for (int i=1;i<=3;i++){
        for (int j=1;j<=10;j++){
            cout<<" "<<a[4][i][j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}


int main(){
    ll h,w; cin >> h >> w;
    string s[h];
    rep(i,h)cin >> s[i];

    int dx[] = {0,1};
    int dy[] = {1,0};
    auto check = [&](int x, int y){
        if(x < 0 || h <= x)return false;
        if(y < 0 || w <= y)return false;
        return true;
    };

    auto dijkstra = [&](int sx, int sy){
        vector<vector<ll>> graph(h, vector<ll>(w,INF));
        graph[0][0] = (s[0][0] == '#') ? 1 : 0;
        using Plll = pair<ll, Pll>;
        priority_queue<Plll, vector<Plll>, greater<Plll>> pq;
        Plll st = {graph[0][0], {0 ,0}};
        pq.emplace(st);
        Plll temp;
        while(!pq.empty()) {
            auto p = pq.top();pq.pop();
            ll c = p.first, x = p.second.first, y = p.second.second;
            if(graph[x][y] < c)continue;
            rep(i,2){
                int nx = x + dx[i], ny = y + dy[i];
                if(!check(nx,ny))continue;
                if(c + 1 > graph[nx][ny])continue;
                if(s[nx][ny] == '#'){
                    if(s[x][y] == '#'){
                        graph[nx][ny] = c;
                        temp = {c, {nx,ny}};
                        pq.emplace(temp);
                    }
                    else {
                        graph[nx][ny] = c + 1;
                        temp = {c+1, {nx, ny}};
                        pq.emplace(temp);
                    }
                }
                else{
                    graph[nx][ny] = c;
                    temp = {c, {nx,ny}};
                    pq.emplace(temp);
                }
            }
            // print(c,x,y);
            // print(graph);
            // print();
        }
        return graph;
    };
    auto graph = dijkstra(0,0);

    // print(graph);
    cout << graph[h-1][w-1] << endl;
}

Measured memory_bytes: 384
x,y,a,b,c=map(int,input().split())
R=sorted(map(int,input().split()),reverse=True)
G=sorted(map(int,input().split()),reverse=True)
N=sorted(map(int,input().split()),reverse=True)
L=sorted(R[:x]+G[:y]+N[:(x+y)],reverse=True)
print(sum(L[:(x+y)]))


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }


/*
--------------------------------------------

	type

--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;

/*
--------------------------------------------

	container

--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())

/*
--------------------------------------------

	repetition

--------------------------------------------
*/
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

/*
--------------------------------------------

	constant

--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

/*

	Optimizer

*/
//#pragma GCC optimize("Ofast")


LL m(LL x, vector<LL>& A, LL& N) {
	LL num = 0;
	REP(N) {
			num += A.end() - lower_bound(A.begin(), A.end(), x-A[i]);
	}
	return num;
}

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

	LL N, M;
	cin >> N >> M;

	vector<LL> A(N);
	REP(N) cin >> A[i];

	M = min(N * N, M);
	sort(A.begin(), A.end());

	vector<LL> S(N+1);
	REP(N) S[i+1] = S[i]+A[i];

	LL left = 2 * A[0] - 1;
	LL right = 2 * A.back() + 1;
	while (right - left != 1) {
			LL center = (left + right) / 2;
			if (m(center, A, N) > M) left = center;
			else right = center;
	}

	// printf("right=%lld, left=%lld\n", right, left);

	LL ans = 0;
	REP(N) {
			auto itr = lower_bound(A.begin(), A.end(), right-A[i]);
			int x = distance(A.begin(), itr);
			// printf("x=%d\n", x);
			ans += A[i] * (N - x);  // 自分が握手に関与する回数
			ans += S.back() - S[x]; // 握手の相手
	}
	ans += (M - m(right, A, N)) * left;
	cout << ans << endl;

	return 0;
}


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod2 = 1000000007;
const ll mod = 998244353;

ll power(int x, int y){
    ll answer = 1;
    lrep(i, 0, y){
        answer *= x;
        answer %= mod;
    }
    return answer;
}
int main(){
  int n;
  cin >> n;
  vector<int>d(n),cnt(100000);
  rep(i, 0, n){
      cin >> d[i];
      cnt[d[i]]++;
  }
  if(d[0]!=0||cnt[0]!=1){
      cout << 0 << endl;
      return 0;
  }
  sort(d.begin(),d.end());
  int p = d[d.size()-1];
  ll ans = 1;
  rep(i, 1, p+1){
      if(cnt[i]==0){
          cout << 0 << endl;
          return 0;
      }
      ans *= power(cnt[i-1], cnt[i]);
      ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3972
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator

void solve() {
    int n;cin>>n;
    int x = (int) sqrt(n);
    cout << x*x <<endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
def main():
	H, W = map(int, input().split())
	S = [""]*H
	for i in range(H):
		S[i] = input()
	r = [[0 for _ in range(W)] for _ in range(H)]
	c = [[0 for _ in range(W)] for _ in range(H)]
	for i in range(H):
		for j in range(W):
			if S[i][j] == "#":
				continue
			r[i][j] = r[i][j-1]+1 if j > 0 else 1
		for j in range(W-2, -1, -1):
			if r[i][j+1] == 0 or r[i][j] == 0:
				continue
			r[i][j] = r[i][j+1]

	for j in range(W):
		for i in range(H):
			if S[i][j] == "#":
				continue
			c[i][j] = c[i-1][j]+1 if i > 0 else 1
		for i in range(H-2, -1, -1):
			if c[i+1][j] == 0 or c[i][j] == 0:
				continue
			c[i][j] = c[i+1][j]

	ans = 0
	for j in range(W):
		for i in range(H):
			ans = max(ans, c[i][j]+r[i][j]-1)
	print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 125528
#include <limits.h>
#include <stdio.h>
#include <string.h>

#include <algorithm>
#include <utility>

using namespace std;

int N;
int cost[10][10];

pair<int, int> getMinCost() {
  // Flood.
  for (int k = 0; k < N; ++k) {
    for (int i = 0; i < N; ++i) {
      for (int j = i + 1; j < N; ++j) {
        if (k == i || k == j) {
          continue;
        }
        if (cost[i][k] != -1 && cost[k][j] != -1) {
          int c = cost[i][k] + cost[k][j];
          if (cost[i][j] == -1 || cost[i][j] > c) {
            cost[i][j] = cost[j][i] = c;
          }
        }
      }
    }
  }
  int sum[10];
  for (int i = 0; i < N; ++i) {
    sum[i] = 0;
    for (int j = 0; j < N; ++j) {
      sum[i] += cost[i][j];
    }
  }
  pair<int, int> result;
  result.second = INT_MAX;
  for (int i = 0; i < N; ++i) {
    if (sum[i] < result.second) {
      result = make_pair(i, sum[i]);
    }
  }
  return result;
}

int main() {
  //freopen("ConvenientLocation.in", "r", stdin);
  int R;
  while (scanf("%d", &R) == 1 && R != 0) {
    N = 0;
    memset(cost, -1, sizeof(cost));
    for (int i = 0; i < 10; ++i) {
      cost[i][i] = 0;
    }
    int a, b, c;
    for (int i = 0; i < R; ++i) {
      scanf("%d%d%d", &a, &b, &c);
      N = max(N, max(a, b));
      if (cost[a][b] == -1 || cost[a][b] > c) {
        cost[a][b] = cost[b][a] = c;
      }
    }
    N++;
    pair<int, int> result = getMinCost();
    printf("%d %d\n", result.first, result.second);
  }
  return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main()
{
          ll n,m;
          cin>>n>>m;
          ll a[n];
          arrin(a,n);
          fri(i,0,n){
                    a[i] /= 2;
          }
          ll ans = a[0];
          fri(i,1,n)
          {
                    ans = (((a[i] * ans)) / (__gcd(a[i], ans)));
                    if(ans>m){
                              break;
                    }
          }
          if(ans>m)
          {cout<<0<<endl;return 0;}
          bool odm = false;
          fri(i,0,n)
          {
                    if(((ans/a[i])%2)==0)
                    {
                              odm = true;
                    }
          }
          if(odm){
                    cout<<0<<endl;
                    return 0;
          }
          ll xx = m/ans;
          cout<<(xx+1)/2<<endl;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e8+1, mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,i,k;
	cin>>n>>k;
	vector<int> dp(n),a(n);
	for(i=0;i<n;i++) cin>>a[i];
	
	for(i=1;i<n;i++){
		dp[i]=INF;
		for(int j=1;j<=k && i-j>=0 ;j++){
			dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]) );
		}
	}
	
	cout<<dp[n-1];
}
// check for any potential overflow before submitting



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

struct Diameter{
    vector<int> center;
    vector<int> diameter_seq;
    int N;

    pair<vector<int>, vector<int>> calc_dist(int start, const vector<int> G[]){
        vector<int> dist(N, -1), prev(N);
        dist[start] = 0;
        prev[start] = -1;
        queue<int> que;
        que.push(start);
        while(que.size()){
            int i = que.front(); que.pop();
            for(auto j : G[i]){
                if(dist[j] == -1){
                    dist[j] = dist[i]+1;
                    prev[j] = i;
                    que.push(j);
                }
            }
        }
        return {dist, prev};
    }

    int calculate(int n, const vector<int> G[]){
        N = n;
        auto res1 = calc_dist(0, G);
        auto d1 = res1.first;
        int v1 = max_element(d1.begin(), d1.end()) - d1.begin();
        auto res2 = calc_dist(v1, G);
        auto d2 = res2.first;
        auto p2 = res2.second;
        int v2 = max_element(d2.begin(), d2.end()) - d2.begin();
        int diam = d2[v2];
        while(v2 != -1){
            diameter_seq.push_back(v2);
            if(d2[v2] == diam/2 || d2[v2] == (diam+1)/2) center.push_back(v2);
            v2 = p2[v2];
        }
        return diam;
    }
};

vector<int> edges[100000];

int main(){
    int N;
    cin >> N;
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }

    Diameter diam;
    diam.calculate(N, edges);
    auto diam_seq = diam.diameter_seq;
    int sz = diam_seq.size();

    bitset<100000> used;
    for(int v : diam_seq) used[v] = true;

    vector<int> ans[2];

    for(int k=0; k<2; k++){
        int num = 1;
        for(int i=0; i<sz; i++){
            int jmp = 0;
            for(int j : edges[diam_seq[i]]){
                if(used[j]) continue;
                if(edges[j].size() > 1){
                    cout << -1 << endl;
                    return 0;
                }
                jmp++;
                ans[k].push_back(num + jmp);
            }
            ans[k].push_back(num);
            num += jmp+1;
        }
        reverse(diam_seq.begin(), diam_seq.end());
    }

    auto min_ans = min(ans[0], ans[1]);
    for(int i=0; i<N; i++) cout << min_ans[i] << " \n"[i==N-1];
    return 0;
}

Measured memory_bytes: 9328
/*Shivam Bhalla */
  /* f2016941@pilani.bits-pilani.ac.in */



  #include <iostream>
  #include <cstdio>
  #include <cstring>
  #include <cstdlib>
  #include <cctype>
  #include <algorithm>
  #include <map>
  #include <vector>
  #include <list>
  #include <set>
  #include <queue>
  #include <deque>
  #include <stack>
  #include <iostream>
  #include <string>
  #include <cmath>
  #include <cassert>
  #include <bits/stdc++.h>
  #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
  using namespace std;
  long long maxv = 1e9;


  int main()
  {
    fast_cin();
    long long l,r;
    cin>>l>>r;
    int ans=INT_MAX;
    if(l/2019==r/2019){
      for(int i=l%2019;i<=r%2019;i++){
        for(int j=l%2019;j<=i;j++){
          if(i==j) continue;
          ans=min(ans,(i*j)%2019);
        }
      }
    }
    else
      ans=0;
    cout<<ans;  
    return 0;
  }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		// [0]:500円, [1]:100円, [2]:50円, [3]:合計
		int[] coin = new int[4];
		Scanner sc = new Scanner(System.in);
		for (int i = 0; i < 4; i++) {
			coin[i] = sc.nextInt();
		}
		sc.close();
		System.out.println(calc(coin));
	}

	public static int calc(int[] a) {
		int[] coin = a;
		int count = 0;
		for (int i = 0; i <= coin[0]; i++) { //500円
			for (int j = 0; j <= coin[1]; j++) { //100円
				for (int k = 0; k <= coin[2]; k++) {//10円
					count += (500 * i + 100 * j + 50 * k) == coin[3] ? 1 : 0;
				}
			}
		}
		return count;
	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define fo(i,s,e) for (int i=(s); i < (e); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define int long long
signed main () {
  int n,ans;
  cin >> n;
  int m=10000000000;
  ans=0;
  vector<int> v(n,1000);
  rep(i,n){
    cin >> v[i];
    m=min(m,v[i]);
    v[i] == m ? ans+=1 : 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
t,f,p[5];main(i){for(;({for(i=t=f=0;i<5;f|=1<<p[i++])scanf("%d\n",p+i),t+=p[i];*p;});)for(i=0;i<5;i++)puts(14^f&&t%5?f%5-p[i]%3?"2":"1":"3");}

Measured memory_bytes: 0
# coding: utf-8
N = int(input())
A = list(map(int,input().split()))
leaf= [-1 for i in range(N+1)]
notleaf = [-1 for i in range(N+1)]
flag=0

if N == 0 and A[0] == 1:
    print(1)
elif N==0 and A[0]!=1:
    print(-1)
elif N != 0 and A[0]>=1:
    print(-1)
else:
    leaf[0]=0
    notleaf[0]=1
    for d in range(1, N+1):
        leaf[d] = A[d]
        notleaf[d] = 2*notleaf[d-1] - leaf[d]
        if notleaf[d]<0:
            flag=1
            print(-1)
            break
    if flag == 1:
        pass
    else:
        sleaf = 0
        for i in range(N+1):
            sleaf += leaf[i]
        
        d1 = 0
        for i in range(N+1):
            d1 += (i+1) * leaf[i]
        
        sleaf -= 1
        for i in range(1,N+1):
            if sleaf>0:
                d1 -= i*( min(sleaf, leaf[i]+notleaf[i] - notleaf[i-1]))
                sleaf -= (leaf[i]+notleaf[i] - notleaf[i-1])
            else:
                break
        print(d1)
    
    
    


Measured memory_bytes: 669532
#include<stdio.h>
int return_min(int a,int b){
  if(a>b)return b;
  else return a;
}

int return_max(int a,int b){
  if(a>b)return a;
  else return b;
}

int main(void)
{
  int h,w,n;
  scanf("%d %d %d",&h,&w,&n);
  int min=return_min(h,w);
  int max=return_max(h,w);
  int count=0;
  while(n>0){
    n-=max;
    min--;
    count++;
  }

  printf("%d\n",count);
}


Measured memory_bytes: 1692
#include <stdio.h>
int main()
{
    int a,b,x,y;
    double m,n,z;
    scanf("%d %d",&a,&b);
    x=(a/b);
    y=(a%b);
    m=a;
    n=b;
    z=(m/n);
    printf("%d %d %lf\n",x,y,z);


    return 0;

}



Measured memory_bytes: 2128
N = int(input())
D = list(map(int, input().split()))

 
MOD = 998244353
 
occ = [0 for i in range(N+5)]
for d in D:
    occ[d] += 1
 
if occ[0] != 1 or D[0] != 0:
    print(0)
    quit()
 
cur = 1
for i in range(1, N+5):
    cur *= pow(occ[i - 1], occ[i])
    cur %= MOD
print(cur % MOD)


Measured memory_bytes: 56152
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a[maxn];
int n;
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	ll l=2,r=2;
	for(int i=n;i;i--){
		if((l-1)/a[i]==r/a[i]){
			puts("-1"); return 0;
		}
		l=((l-1)/a[i]+1)*a[i];
		r=r/a[i]*a[i]+a[i]-1;
	}
	writesp(l); writeln(r);
	return 0;
}

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

int main()
{
  long N, W;
  cin >> N >> W;
  long w[105] = {}, v[105] = {};
  long sum_value = 0;
  for (int i = 1; i <= N; i++)
  {
    cin >> w[i] >> v[i];
    sum_value += v[i];
  }
  
  long sum_weight[105][100005] = {}; // N行 sum_value列
  for (int i = 1; i <= N; i++)
  {
    for (int j = 1; j <= sum_value; j++)
    {
      sum_weight[i][j] = 1000000000;
    }
  }
  sum_weight[1][v[1]] = w[1];
  
  for (int i = 2; i <= N; i++)
  {
    long wi = w[i], vi = v[i];
    
    for (int j = sum_value; j >= 1; j--)
    {
      sum_weight[i][j] = sum_weight[i - 1][j]; // 上の行に書いてある重さを下の行に書き写す
      if (sum_weight[i][j] > 0)
      {
        sum_weight[i][j + vi] = min(sum_weight[i][j + vi], sum_weight[i][j] + wi);
      }
    }
    
    sum_weight[i][vi] = min(sum_weight[i][vi], wi);
  }
  
  for (int j = sum_value; j >= 1; j--)
  {
    if (sum_weight[N][j] >= 1 && sum_weight[N][j] <= W)
    {
      cout << j << endl;
      return 0;
    }
  }
  
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li np[200200][27];
li cnt[200200];

li cur[26];

int main() {
    string s;
    cin >> s;
    li n = sz(s);

    rep(i, 26) {
        cur[i] = n + 1;
        cnt[n + 1] = 0;
    }

    for (li i = n; i >= 0; i--) {
        cnt[i] = INF;
        rep(j, 26) {
            np[i][j] = cur[j];
            cnt[i] = min(cnt[i], cnt[cur[j]] + 1);
        }
        if (i > 0)cur[s[i - 1] - 'a'] = i;
    }
    string res = "";

    li now = 0;
    while (now < n + 1) {
        li mi = INF;
        char mic = 'A';
        li ne = -1;
        rep(j, 26) {
            li next_pos = np[now][j];
            li next_cnt = cnt[next_pos];
            if (next_cnt < mi) {
                mi = next_cnt;
                mic = j + 'a';
                ne = next_pos;
            }
        }
        res = res + mic;
        now = ne;
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 47468
inp = input().split()
n = int(inp[0])
m = int(inp[1])
favorite = [] #　i番目の人が好きなものの集合のリスト
for i in range(n):
    tmp = []
    tmp_inp = input().split()
    k = int(tmp_inp[0])
    for i in range(k):
        tmp.append(int(tmp_inp[i+1]))
    favorite.append(set(tmp))


def intersect_set(list):  # 集合のリストを受け取って、それらの積集合を返す
    result = list[0]
    for i in range(len(list)-1):
        result = result.intersection(list[i+1])
    return result

print(len(intersect_set(favorite)))


Measured memory_bytes: 3064
#include <iostream>
#include <assert.h>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;

typedef long long ll;

ll c[60][60];

int main() {
	int n, l, r;
	cin >> n;
	cin >> l >> r;
	assert(l <= r);

	vector <ll> a(n);

	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	
	c[0][0] = 1;
	for (int i = 0; i < 59; i++) {
		for (int j = 0; j < 59; j++) {
			c[i+1][j] += c[i][j];
			c[i+1][j+1] += c[i][j];
		}
	}

	int x = l-1;
	int y = l-1;
	while (x && a[x-1] == a[x]) x--;
	while (y+1 < n && a[y] == a[y+1]) y++;
	
	ll cnt = 0;
	int all = y - x + 1;

	if (!x) {
		for (int i = l; i <= r; i++) {
			cnt += c[all][i];
		}
	} else {
		cnt = c[all][l-x];
	}

	cout << fixed << setprecision(10) << (double) accumulate(a.begin(), a.begin() + l, 0LL) / l << "\n";
	cout << cnt << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define REPR(i,n) for(int i=(int)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(int i=(int)(b)-1,_a=(int)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	while(cin>>S) {
		ll N = S.size();
		set<char> tb = {'A','C','G','T'};
		ll ans = 0;
		REP(i, N) RANGE(l, 1, N-i+1) {
			string s = S.substr(i, l);
//			DD(s);
			ll ok = 1;
			for(char c:s) if(!tb.count(c)) ok=0;
			if(ok) maxUpdate(ans, (ll)l);
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            do {
                int c = a % b;
                a = b;
                b = c;
            } while(b != 0);
            System.out.println(a);
        }
    }
}


Measured memory_bytes: 26396
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr)
#define fix(n) fixed << setprecision(n)

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    fast_io();
    
    ll k,a,b;
    cin >> k >> a >> b;
    ll adiv = roundup(a,k);
    bool is_okey = (adiv * k) <= b;

    cout << (is_okey ? "OK" : "NG") << endl;
    return 0;
}


Measured memory_bytes: 3120
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ITP1-ITP1_8-A

Character - Toggling Cases
Time Limit : 1 sec, Memory Limit : 65536 KB
??§????????¨?°????????????\?????????

????????????????????????????°?????????¨??§???????????\????????????????????°????????????????????????????????????
Input

????????????1???????????????????????????
Output

????????????????????????????°?????????¨??§???????????\??????????????????????????????????????????????????¢????????????????????\???????????????????????????????????????????????????
Constraints

    ??\?????????????????????????????? < 1200

Sample Input

fAIR, LATER, OCCASIONALLY CLOUDY.

Sample Output

Fair, later, occasionally cloudy.

=end
fh=STDIN
#fh=open("IPT1_8_A.txt")
s=fh.gets.chomp
puts s.swapcase

Measured memory_bytes: 8572
import sys
import math
readline = sys.stdin.readline

K = int(readline())
A = reversed(list(map(int, readline().split())))

a_min = 2
a_max = 2
for a in A:
    a_min = math.ceil(a_min / a) * a
    a_max = a * (a_max // a) + a - 1
    if a_min > a_max:
        print(-1)
        exit()
print('{} {}'.format(str(a_min), str(a_max)))


Measured memory_bytes: 14252
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define rint register int
#define rep(i,l,r) for(rint i=l;i<=r;i++)
#define per(i,l,r) for(rint i=l;i>=r;i--)
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back 
#define fir first
#define sec second
template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
int read(){
  int x=0,f=0;
  char ch=getchar();
  while(!isdigit(ch))f|=ch=='-',ch=getchar();
  while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
  return f?-x:x;
}
const int N=200005;
int ans=0;
int n,d;
int x[N],y[N];
int main(){
  n=read(),d=read();
  for(int i=1;i<=n;i++)x[i]=read(),y[i]=read();
  for(int i=1;i<=n;i++){
    if(1ll*x[i]*x[i]+1ll*y[i]*y[i]<=1ll*d*d)ans++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 5252
#include <iostream>
#include <cstdio>
#define INF 1e9
#define eps 1e-6
typedef long long ll;
using namespace std;

inline int max(int a, int b){
	return a > b ? a : b;
}

inline int min(int a, int b){
	return a < b ? a : b;
}

int n, a[200010], l, r;

bool check(int x){
	int sum = 0, now = 1;
	for(int i = 1; i <= n; i++)
		if(now != a[i])
			sum++;
		else
			now++;
	return sum <= x;
}

int main(){

	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	l = 0, r = n;
	while(l < r){
		int mid = (l + r) >> 1;
		if(check(mid)) r = mid;
		else l = mid + 1;
	}
	if(l == n && l != 0) cout << "-1" << endl;
	else cout << l << endl;

	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];
            for (int i = 0; i < values.length; i++) {
                values[i] = i + 1;
            }
            for (int i = 0; i < n; i++) {
                String str = sc.next();
                String[] ab = str.split(",");
                int a = Integer.parseInt(ab[0]) - 1;
                int b = Integer.parseInt(ab[1]) - 1;

                int x = values[a];
                values[a] = values[b];
                values[b] = x;
            }
            for (int i = 0; i < w; i++) {
                System.out.println(values[i]);
            }
        }
    }
}



Measured memory_bytes: 26180
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
using vv = vector<vector<ll>>;
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;}

const long long inf = 1ll << 60;
const long long mod = 1000000007;

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

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


Measured memory_bytes: 3632
//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 forzm(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(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;
    ldb n;
    cin>>n;
    ldb k=floor(n/2);
    if(ceil(n/2)==floor(n/2))cout<<0.5;
    else
    {
        cout<<deci(10)<<(k+1)/n;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int N,M;
int exist[100008];
int uf[100008];
int getpa(int x) {
	if(uf[x]==x) return x;
	uf[x]=getpa(uf[x]);
	return uf[x];
}
int main() {
	scanf("%d%d",&N,&M);
	int Lmin=M+1;
	for(int i=0;i<N;i++) {
		int K,Lf,L;
		scanf("%d",&K);
		for(int j=0;j<K;j++) {
			scanf("%d",&L);
			if(Lmin>L) Lmin=L;
			if(j) {
				if(exist[L]==0) {
					exist[L]=1;
					uf[L]=L;
				}
				uf[getpa(L)]=getpa(Lf);
			} else {
				if(exist[L]==0) {
					exist[L]=1;
					uf[L]=L;
				}
				Lf=L;
			}
		}
	}
	for(int i=1;i<=M;i++) {
		if(exist[i]) if(getpa(i)!=getpa(Lmin)) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}


Measured memory_bytes: 896