akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

int main(){
    string s;
    cin >> s;
    string ans[26];
    for (int i = 0; i < 26;i++){
        ans[i] += ('a' + i);
    }
    for (int i = 0; i < s.size(); i++)
    {
        int x = s[i] - 'a';
        string minstr = ans[0];
        for (int j = 1; j < 26; j++)
        {
            if(minstr.size()>ans[j].size()){
                minstr = ans[j];
            }
            else if(minstr.size() == ans[j].size()){
                if(minstr>ans[j]){
                    minstr = ans[j];
                }
            }
        }
        ans[x] = minstr;
        ans[x] += s[i];
    }
    string minstr;
    minstr = ans[0];
    for (int i = 1; i < 26; i++)
    {
        if(minstr.size()>ans[i].size()){
            minstr = ans[i];
        }
        else if(minstr.size() == ans[i].size()){
            if(minstr>ans[i]){
                minstr = ans[i];
            }
        }
    }
    cout << minstr << endl;
    return 0;
}


Measured memory_bytes: 1000
#include<stdio.h>

main(){
int i,N;
int a,b,c;
    scanf("%d",&N);
    for(i=0;i<N;i++){
      scanf("%d %d %d",&a,&b,&c);
      if(a>b&&a>c){
          if(a*a==b*b+c*c) printf("YES\n");
	  else printf("NO\n"); 
      }
      else if(b>a&&b>c){
          if(b*b==a*a+c*c) printf("YES\n");
	  else printf("NO\n"); 
      }
      else{
          if(c*c==a*a+b*b) printf("YES\n");
	  else printf("NO\n"); 
      }
   }
return 0;
}

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

using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;



int main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall


    ini(n);
    float tmp = 0;
    float tmp1 = 1;
    FOR(i,0,n){
        float x;
        in(x);
        tmp+=1/x;
    }
    cout<<setprecision(14)<<1/tmp;
    return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

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

    vector <int> a, b, c;

    a = vector <int>(N);
    b = vector <int>(N);
    c = vector <int>(N);

    for(int i=0;i<N;i++){cin >> a[i];}
    for(int i=0;i<N;i++){cin >> b[i];}
    for(int i=0;i<N;i++){cin >> c[i];}

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    long long ans = 0;
    for(int i=0;i<N;i++){
        long long _aa = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        long long _cc = N - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
        ans = ans + _aa * _cc;
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void){
    char name1[20],name2[20],name3[20],name4[20],name5[20];
    char name6[20],name7[20],name8[20],name9[20];
    int a1,a2,a3,a4,a5,a6,a7,a8,a9;
    int b1,b2,b3,b4,b5,b6,b7,b8,b9;
    scanf("%s %d %d",name1,&a1,&b1);
    scanf("%s %d %d",name2,&a2,&b2);
    scanf("%s %d %d",name3,&a3,&b3);
    scanf("%s %d %d",name4,&a4,&b4);
    scanf("%s %d %d",name5,&a5,&b5);
    scanf("%s %d %d",name6,&a6,&b6);
    scanf("%s %d %d",name7,&a7,&b7);
    scanf("%s %d %d",name8,&a8,&b8);
    scanf("%s %d %d",name9,&a9,&b9);
    printf("%s %d %d\n",name1,a1+b1,a1*200+b1*300);
    printf("%s %d %d\n",name2,a2+b2,a2*200+b2*300);
    printf("%s %d %d\n",name3,a3+b3,a3*200+b3*300);
    printf("%s %d %d\n",name4,a4+b4,a4*200+b4*300);
    printf("%s %d %d\n",name5,a5+b5,a5*200+b5*300);
    printf("%s %d %d\n",name6,a6+b6,a6*200+b6*300);
    printf("%s %d %d\n",name7,a7+b7,a7*200+b7*300);
    printf("%s %d %d\n",name8,a8+b8,a8*200+b8*300);
    printf("%s %d %d\n",name9,a9+b9,a9*200+b9*300);
    return 0;
}


Measured memory_bytes: 2132
#include <cstdio>
using namespace std;

int S;
int X, Y, W, H;
int N;

int main(){
    for(scanf("%d", &S); S--;){
        int ans = 0;
        scanf("%d%d%d%d%d", &X, &Y, &W, &H, &N);
        for(int i = 0; i < N; i++){
            int x, y;
            scanf("%d%d", &x, &y);
            if(X <= x && x <= X+W &&
               Y <= y && y <= Y+H){
                ++ans;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
int n,k;
vector<int> a;
vector<int > dp;
// run time error
int solve(int score){
	if(score<a[0]) dp[score]=0;
	else if(dp[score]!=-1) return dp[score];
	else{	
		for(int i=n-1;i>=0;i--){
			if(score>=a[i]&&solve(score-a[i])==0){dp[score]=1;return dp[score];}
		}
		dp[score]=0;
	}
	return dp[score];
}
	
		
int main(){
	cin >>n>>k;
	dp.assign(k+1,-1);
	a.assign(n,0);
	for(int i=0;i<n;i++) cin>>a[i];

	for(int i=n-1;i>=0;i--){
		if(solve(k-a[i])==0){
			cout<<"First";
			return 0;
		}
	}
	cout<<"Second";
	return 0;
	

/*	for(int i=1;i<=k;i++){
		for(int j=0;j<n;j++){
			if(i-a[j]&&dp[i-a[j]*/
}




Measured memory_bytes: 5376
/*
THE BEST IS YET TO COME
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define r(i,s,l) for(int i=s;i<l;i++)
#define mod 1000000007
#define INT_BITS 32
#define ld long double
#define pp pair<long long,long long>
#define ss second
#define ff first
#define N 2000005
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
int main()
{
    fast();
    ld n,m,sum=0;
    cin>>n>>m;
    vector<ld> a(n);
    r(i,0,n)
    {
        cin>>a[i];
        sum+=a[i];
    }
    ld x = float(sum)/(4*m);
    r(i,0,n)
    {
        if(a[i]>=x)
        m--;
    }
    if(m>0)
    cout<<"No";
    else
    {
        cout<<"Yes";
    }
    

	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

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

int main(){
    std::ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll v[n];
    for(int i=0;i<n;++i)
    {
        cin >> v[i];
    }

    ll ret = 0;
    for(int i=0;i<=k;++i)
    {
        for(int j=0;j<=k-i;++j)
        {
            if(i + j > n) {
                continue;
            }

            int remaining_steps = k - (i + j);
            ll sum = 0;
            vector<ll> gems;
            for(int jj = 0; jj < i; ++jj)
            {
                sum += v[jj];
                gems.PB(v[jj]);
            }

            for(int jj = 0; jj < j; ++jj)
            {
                sum += v[n-1 - jj];
                gems.PB(v[n - 1 - jj]);
            }

            sort(gems.rbegin(), gems.rend());
            while(!gems.empty() && remaining_steps > 0 && gems.back() < 0)
            {
                sum -= gems.back();
                gems.pop_back();
                remaining_steps--;
            }

            ret = max(ret, sum);
        }
    }

    cout << ret << endl;
}

Measured memory_bytes: 256
import sys
inpt = sys.stdin.readline
 
def count(N, X, Ls):
  curr = 0
  if Ls[0]>X:
    return 0
  
  for i in range(N):
    l_im1 = Ls[i]
    curr += l_im1
    if curr > X:
      return i+1
  return N+1
 
N, X = [int(d) for d in inpt().strip().split()]
Ls = [int(d) for d in inpt().strip().split()]
print(count(N, X, Ls))

Measured memory_bytes: 3060
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long ll;

int main(void) {

    ll h, w;
    cin >> h >> w;

    if(h % 3 == 0 || w % 3 == 0){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1e9;
    ans = min(ans, w);
    ans = min(ans, h);

    for(int i = 1; i < w; i++){
        ll r0 = h * (w - i);
        ll r1 = i * (h / 2);
        ll r2 = i * (h - h / 2);
        ll smax = max(r0, max(r1, r2));
        ll smin = min(r0, min(r1, r2));
        ans = min(ans, smax - smin);
    }

    for(int i = 1; i < h; i++){
        ll r0 = w * (h - i);
        ll r1 = i * (w / 2);
        ll r2 = i * (w - w / 2);
        ll smax = max(r0, max(r1, r2));
        ll smin = min(r0, min(r1, r2));
        ans = min(ans, smax - smin);
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
	bool ok = false;
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < (int)s.size(); i++) {
		if (s == t) {
			ok = !ok;
			break;
		}
		s.push_back(s[0]);
		s.erase(s.begin());
	}
	if (ok)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Main main = new Main();
		main.solveD();
	}

	private void solveA() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		System.out.println(N * A < B ? N * A : B);
	}

	private void solveB() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int tmp = N;
		int sum = 0;
		while (tmp > 0) {
			sum += tmp % 10;
			tmp /= 10;
		}
		if (N % sum == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	private void solveD() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int C = sc.nextInt();
		int[][] M = new int[C + 1][];
		for (int j = 1; j <= C; j++) {
			M[j] = new int[100001];
		}
		for (int i = 1; i <= N; i++) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			int c = sc.nextInt();
			for (int j = s; j <= t; j++) {
				M[c][j] = 1;
			}
		}
		int max = 0;
		for (int i = 1; i <= 100000; i++) {
			int sum = 0;
			for (int j = 1; j <= C; j++) {
				if (M[j][i] == 1) {
					sum++;
				}
			}
			if (max < sum) {
				max = sum;
			}
		}
		System.out.println(max);
	}
}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cerr<<#x<<" = "<<x<<endl

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    li n,x,M;

    cin>>n>>x>>M;

    if(x==1)
    {
        cout<<n;
        return;
    }

    if(x==0)
    {
        cout<<0;
        return ;
    }

    vi v(2e5);

    li ans=0;

    while(n>0)
    {
        ans+=x;

        x*=x;

        if(x>=M)
        {
            n--;
            break;
        }   
        n--;
    }

    if(n<=0)
    {
        cout<<ans;
        return ;
    }

    vi freq(2e5,-1);

    li pos=0;

    while(n>0)  
    {
        n--;
        x%=M;

        if(freq[x]==-1)
        {
            ans+=x;
            debug(ans);
            freq[x]=pos++;
            v[pos-1]=x;
        }
        else
        {
            n++;
            break;
        }

        x*=x;
        // n--;
    }

    if(n<=0)
    {
        cout<<ans;
        return;
    }

    debug(ans);

    li sz=pos;
    pos=freq[x];

    
    li sum=0,deno=0;

    f(i,pos,sz-1)
    {
        sum+=v[i];
        deno++;
    }

    li tp=n/deno;
    li rem=n%deno;

    ans+=tp*(sum);

    f(i,pos,pos+rem-1)
    {
        ans+=v[i];
    }

    // ans+=pre[rem-1];

    cout<<ans;
}

int main()
{    
    //remove this in kickstart

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li t=1;

    // cin>>t;

    f(i,1,t)
    {
        // cout<<"Case #"<<i<<": ";

        solve();
    }

    return 0;
}


Measured memory_bytes: 6364
//B - Count Balls

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    long long n,a,b;

    cin >> n >> a >> b;


    long long cnt = n / (a + b);
    long long amari = n % (a + b);

    if (amari > a) {
        cout << cnt * a + a << endl;
    }else{
        cout << cnt * a + amari << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define PER(i,n,a) for(ll i=n;i>a;i--)
#define REP1(i,a,n) for(ll i=a;i<=n;i++)
#define forit(it,x) for(auto it=(x).begin();it!=(x).end();++it)
#define ull unsigned long long int
#define ld long double
#define prec(n) fixed<<setprecision(n)
#define test ll t; cin>>t; while(t--)
#define re return 0
#define pb push_back
#define PI 3.1415926535897932384626
#define MOD (ll)1000000007
#define fi first
#define se second
#define eb emplace_back
#define vll vector<ll>
#define vi  vector<int>
#define mpll map<ll,ll>
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
const ll MAXI = (ll)1e9+7;
int main(){
    IOS;
/*    test{
        int n;
        cin>>n;
        int ar[n];
        REP(i,a,n){
           cin>>ar[i];
        }
    }
    */
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22){
        cout<<"bust"<<"\n";
    }else{
        cout<<"win"<<"\n";
    }
re;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define INF 10000000000000009
#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

signed main(){
    int N;
    int h[114514];
    int dp[114514]={};
    cin >> N;
    REP(i,N){cin >> h[i];}
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<N;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[N-1] << endl;
    return 0;
}   


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

int main(){
  int n,m,k;
  cin >> n >> m >> k;
  bool ans=false;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
      if(i*j+(n-i)*(m-j)==k) ans=true;
    }
  }
  cout << (ans?"Yes":"No") << endl;
}

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

int main(){
	char yoko[7][6];//5 * 4
	char tate[6][7];//4 * 5
	int x, y;//position
	char dir;//next direction
	
	for(int i = 0; i < 4; i++){
		scanf("%s", yoko[i]);
		scanf("%s", tate[i]);
	}
	scanf("%s", yoko[4]);
	
	x = 0; y = 0; dir = 'R';
	while(true){
		printf("%c", dir);
		switch (dir){
			case 82://right
				x++;
				if(y > 0 && tate[y - 1][x] == '1') dir = 'U';
				else if(yoko[y][x] == '1') dir = 'R';
				else if(tate[y][x] == '1') dir = 'D';
				else dir = 'L';
				break;
			case 68://down
				y++;
				if(yoko[y][x] == '1') dir = 'R';
				else if(tate[y][x] == '1') dir = 'D';
				else if(x > 0 && yoko[y][x - 1] == '1') dir = 'L';
				else dir = 'U';
				break;
			case 76://left
				x--;
				if(tate[y][x] == '1') dir = 'D';
				else if(x > 0 && yoko[y][x - 1] == '1') dir = 'L';
				else if(y > 0 && tate[y - 1][x] == '1') dir = 'U';
				else dir = 'R';
				break;
			case 85://up
				y--;
				if(x > 0 && yoko[y][x - 1] == '1') dir = 'L';
				else if(y > 0 && tate[y - 1][x] == '1') dir = 'U';
				else if(yoko[y][x] == '1') dir = 'R';
				else dir = 'D';
				break;
			default :
				break;
		}
		
		if(x == 0 && y == 0) break;
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 928
k = int(input())
from queue import Queue

queue = Queue()
for i in range(1, 10):
    queue.put(i)

n = 0
while n < k:
    i = queue.get()
    n += 1
    j = i % 10
    if j == 0:
        queue.put(i*10)
        queue.put(i*10+1)
    elif j == 9:
        queue.put(i*10+8)
        queue.put(i*10+9)
    else:
        queue.put(i*10+j-1)
        queue.put(i*10+j)
        queue.put(i*10+j+1)

print(i)

Measured memory_bytes: 12456
import java.util.*;
 
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int x = sc.nextInt();
    int a = sc.nextInt();
    
	if(x < a){
      System.out.println("0");
    }else{
      System.out.println("10");
    }
 
 
  }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int deg[5]= {};
    int i;
    FOR0(i, 3)
    {
        int u, v;
        cin>>u>>v;
        u--;v--;
        deg[u]++;
        deg[v]++;
    }
    FOR0(i, 4)
    {
        if(deg[i]>2) break;
    }
    if(i==4) cout<<"YES";
    else cout<<"NO";
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char gra[110][110];
int m, n;
int dirx[] = {0, 0, -1, 1},diry[] = {-1,1,0,0}, ans;

void DFS(int r,int c,char k){
	gra[r][c] = 0;
	for(int i = 0; i < 4; i++){
		int dr = r + dirx[i];
		int dc = c + diry[i];
		if(dr >= 0 && dr<m && dc >= 0 && dc < n && gra[dr][dc] == k){
			DFS(dr, dc, k);
		}
	}
}

int main(){
	while(scanf("%d%d", &m, &n) && m+n){
		for(int i = 0;i < m; i++){
			scanf("%s", gra[i]);
		}
		ans = 0;
		for(int i = 0;i < m; i++){
			for(int j = 0; j < n; j++){
				if(gra[i][j]){
					ans++;
					DFS(i, j, gra[i][j]);
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


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

#define MAX 20050
#define INF 1e9

void push(char);
char pop(void);

int pos,len;
char st[MAX];

int main(){
  double sum = 0;
  int depth[MAX],Min[MAX],mini;
  int i,S[MAX],pool = 0,ans = 0;
  char str[MAX],ch;

  scanf("%s" ,str);
  len = (int)strlen(str); pos = 0;

  for(i = 0 ; i < len ; i++){
    if(str[i] == '\\'){
      depth[i] = ++pool;
    }else if(str[i] == '/'){
      depth[i] = --pool;
    }else{
      depth[i] = pool;
    }
  }
  
  mini = INF;
  for(i = len-1 ; i >= 0 ; i--){
    if(depth[i] < mini){
      mini = depth[i];
    }
    Min[i] = mini;
  }

  pool = 0;
  for(i = 0 ; i < len ; i++){
    if(str[i] == '\\'){
      if(i != len-1 && depth[i] == Min[i]) continue;
      push(str[i]);
    }else if(str[i] == '/'){
      ch = pop();
      if(ch != '#'){
	sum += ((pos+1) - 0.5)*2;
      }
    }else{
      sum += pos; 
    }

    if(sum > 0 && (pos == 0)){
      S[pool++] = sum;
      ans += sum;
      sum = 0;
    }
  }

  printf("%d\n%d" ,ans ,pool);
  for(i = 0 ; i < pool ; i++){
    printf(" %d" ,S[i]);
  } 
  printf("\n");

  return 0;
}

void push(char ch){
  st[pos++] = ch;
}

char pop(){
  if(pos == 0){
    return '#';
  }
  return st[--pos];
}

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

#define pb push_back

using namespace std;

vector<int> gph[100005];
int degree[100005],d[100005];

int main()
{
  int n,m,ans=0,iu,iv;
  queue<int> q;

  scanf("%d%d",&n,&m);
  for(int c=0;c<m;c++)
  {
    scanf("%d%d",&iu,&iv);
    gph[iu].pb(iv);
    degree[iv]++;
  }
  for(int c=1;c<=n;c++)
  if (degree[c]==0)q.push(c);
  while(!q.empty())
  {
    for(int c=0;c<gph[q.front()].size();c++)
    {
      degree[gph[q.front()][c]]--;
      if (degree[gph[q.front()][c]]==0)q.push(gph[q.front()][c]);
      d[gph[q.front()][c]]=max(d[gph[q.front()][c]],d[q.front()]+1);
      ans=max(ans,d[gph[q.front()][c]]);
    }
    q.pop();
  }
  printf("%d\n",ans);
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define long long LL
const int N=1000005;
const int M=1e9+7;
int n,m,k,ans,f[N],v[N],sum;
int fp(int x,int y){int s=1;
for(;y;y>>=1){if(y&1)s=1ll*s*x%M;
x=1ll*x*x%M;}return s;}
int C(int x,int y){
return 1ll*f[x]*v[y]%M*v[x-y]%M;}
signed main(){scanf("%d%d%d",&n,&m,&k);
f[0]=v[0]=1;sum=n+m+k;
for(int i=1;i<=sum;i++)f[i]=1ll*f[i-1]*i%M;
v[sum]=fp(f[sum],M-2);for(int i=sum-1;i;i--)
v[i]=1ll*v[i+1]*(i+1)%M;if(m<k)swap(m,k);int q=1;
for(int i=n;i<=sum;i++){if(k+n>=i){
(ans+=1ll*C(i-1,n-1)*fp(3,sum-i)%M*q%M)%=M;
if(k+n!=i)q=q*2%M;}
else if(n+m>=i){q=q*2-C(i-n-1,k);q=(q%M+M)%M;
(ans+=1ll*q*C(i-1,n-1)%M*fp(3,sum-i)%M)%=M;}
else{q=q*2-C(i-n-1,k);q=(q%M+M)%M;
q=(q-C(i-n-1,i-n-m-1)+M)%M;
(ans+=1ll*q*C(i-1,n-1)%M*fp(3,sum-i)%M)%=M;}
}printf("%d\n",(ans+M)%M);return 0;}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, H, W;
  int x=0;
  cin >> H >> W >> N;
  int y=H*W;
  
  for (int i=0; i<H+1; i++) {
    for (int j=0; j<W+1; j++) {
      if (j*H+i*W>=N) {
        x += j+i;
        if (x<=y) y=x;
        x=0;
        break;
      }
    }
  }
  
  cout << y << endl;

  return 0;
  
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define mp make_pair
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
    ll N,M,Q;
    cin >> N >> M >> Q;
    vvl cnt(N+1,vl(N+1,0));
    rep(i,M){
        ll L,R;
        cin >> L >> R;
        cnt[L][R]++;
    }
    FOR(i,0,N+1){
        FOR(j,1,N+1){
            cnt[i][j]+=cnt[i][j-1];
        }
    }
    FOR(i,1,N+1){
        FOR(j,0,N+1){
            cnt[i][j]+=cnt[i-1][j];
        }
    }
    rep(i,Q){
        ll p,q;
        cin >> p >> q;
        p--;
        cout << cnt[p][p]+cnt[q][q]-cnt[p][q]-cnt[q][p] << endl;
    }
}

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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multi_set;

#define mod         1000000007
#define pi          acos(-1.0)
#define eps         1e-9


#define fast       ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define fs          first
#define sc          second
#define pb         push_back
#define sp          printf(" ")
#define nl          '\n'
#define all(a) a.begin(),a.end()
#define unique(c) (c).resize(unique(all(c)) - (c).begin())
#define itn int

#define set0(a)     memset(a,0,sizeof(a))
#define setneg(a)   memset(a,-1,sizeof(a))
#define setinf(a)   memset(a,126,sizeof(a))

#define REP(i,start,end) for (int i = start; i <=end; i++)
#define RREP(i,end,start) for (int i=end; i>=start ;i--)

typedef long long LL;
LL INF=1e18;
LL dp[100005];

void solve()
{
    REP(i,1,100004)
        dp[i]=INF;
    dp[0]=0;
    int n,weight;
    cin>>n>>weight;
    REP(i,1,n)
    {
        LL w,v;
        cin>>w>>v;
        RREP(j,100000,0)
            if(dp[j]!=INF)
                dp[j+v]=min(dp[j+v],dp[j]+w);
    }
    int ans=0;
    REP(i,0,100000)
    {
        if(dp[i]<=weight)
            ans=i;
    }
    cout<<ans<<nl;
    
}
int main()
{
    fast;
        solve();
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e4)
#define pi acos(-1)
using namespace std;

int n, m, dp[1<<8][10];
bool mps[10][10];

int main()
{
    mem(mps, 0);
    scanf("%d%d", &n, &m);
    for(int i = 1, a, b;i <= m;i++)
    {
        scanf("%d%d", &a, &b);
        mps[a][b] = mps[b][a] = 1;
    }
    mem(dp, 0);
    dp[1][1] = 1;
    for(int i = 0;i < (1<<n);i++)
    {
        for(int j = 1;j <= n;j++)
        {
            if((i>>(j - 1))&1)
            {
                for(int k = 1;k <= n;k++)
                {
                    if(!((i>>(k - 1))&1)&&mps[j][k])
                    {
                        int st = i + (1<<(k - 1));
                        dp[st][k] += dp[i][j];
                    }
                }
            }
        }
    }
    int ans = 0;
    for(int i = 2;i <= n;i++)
        ans += dp[(1<<n) - 1][i];
    printf("%d\n", ans);
	return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	priority_queue<Pl> d;
	int N; cin >> N;
	vll A(N), B(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
		d.emplace(A[i]+B[i], i);
	}

	ll point = 0;
	for (int i = 0; i < N; i++) {
		int idx = d.top().second; d.pop();
		if (i&1) point -= B[idx];
		else point += A[idx];
	}
	cout << point << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}



Measured memory_bytes: 6868
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n, m;
  cin >> n >> m;
  vector<ll> divi; //mの約数
  for (ll i = 1; i*i <= m; ++i) {
    if (m % i == 0) {
      divi.emplace_back(i);
      divi.emplace_back(m/i);
    }
  }
  sort(all(divi));
  int itr = lower_bound(all(divi), n) - divi.begin();
  ll ans = m / divi[itr]; //n以上の最大の約数 : divi[itr]
  cout << ans << endl;
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    int cnt=0;
    for(int i=1; i<s.size(); i++){
        if(s.at(i)!=s.at(i-1)) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3712
#include<iostream>
using namespace std;
int main()
{ int a,b,c;
   cin>>a>>b>>c;
     int temp1=a;
     int temp2=b;
     int temp3=c;
 
     a=temp3;
     b=temp1;
     c=temp2;
 cout<<a<<" "<<b<<" "<<c;
}

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

using namespace std;

#define int long long

bool codejam = 0;

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}

void solve() {	
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m,d;
	cin>>m>>d;
	int c=0;
	for(int i=22;i<=d && i<=99;i++)
	{
		int a=i%10;
		int b=i;
		b=b/10;
		b=b%10;
		if((a)>=2)
		{
			if(((a) * (b))<=m )
			{
				c++;
			}
		}
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    int val[11][11];
    int N, D, count=0;
    cin>>N>>D;
    rep(i, N) rep(j, D) cin>>val[i][j];
    rep(i, N) for(int j=i+1; j<N; j++){
        int surp=0;
        rep(k, D) surp+=(val[i][k]-val[j][k])*(val[i][k]-val[j][k]);
        if(((int)sqrt(surp))*((int)sqrt(surp))==surp)
            count++;
    }
    cout<<count<<endl;
    return 0;
}


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

asum=sum(alist)
ans_list=[-1]*N

minus_even=sum(alist[1:N:2])
minus_odd=sum(alist[2:N:2])

for i in range(N//2):
  ans_list[2*i] = asum-2*minus_even
  ans_list[2*i+1] = asum-2*minus_odd
  
  minus_even += alist[(2*i+N)%N]-alist[(2*i+1)%N]
  minus_odd += alist[(2*i+N+1)%N]-alist[(2*i+2)%N]
  
ans_list[-1]=asum-2*minus_even
  
ans_list_str=map(str,ans_list)  
print(" ".join(ans_list_str))

Measured memory_bytes: 19568
M=998244353;N=gets.to_i;v=$<.map{|e|Complex(*e.split.map(&:to_i))};h={};r=2**N%M+~N;[*0...N].combination(2){|i,j|h[x=[i,j]]||((j+1...N).map{|k|((v[j]-v[k]).conj*(v[i]-v[k])).imag.abs<1e-9&&x<<k};r=(r-2**(l=x.size)-~l)%M;x.combination(2){|a,b|h[[a,b]]=1})};p r

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

int read() {
    int ans=0,flag=1;
    char ch=getchar();
    while( (ch>'9' || ch<'0') && ch!='-' ) ch=getchar();
    if(ch=='-') flag=-1,ch=getchar();
    while(ch>='0' && ch<='9') ans=ans*10+ch-'0',ch=getchar();
    return ans*flag;
}

int main(){
	int n,a,b;
	cin >> n >> a >> b;
	int ans = n*a;
	if(n*a > b)ans = b;
	cout << ans;
	return 0;
}

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

int main(){
    int N, T;
    cin >> N >> T;
    int c[N], t[N];
    for(int i = 0;i < N; ++i){
        cin >> c[i] >> t[i];
    }

    int min = 1001;
    for(int i = 0;i < N; ++i){
        if(t[i] <= T){
            if(c[i] <= min){
                min = c[i];
            }
        }
    }
    if(min == 1001){
        cout << "TLE" << endl;
        return 0;
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int N, K, x[100001];
    cin >> N >> K;
    for (int i = 1; i <= N; ++i) {
        cin >> x[i];
    }
    long long res = 1 << 30;
    for (int l = 1; l <= N - K + 1; ++l) {
        int r = l + K - 1;
        long long a_xl = abs(x[l]);
        long long a_xr = abs(x[r]);
        if (a_xl < a_xr) {
            res = min(res, a_xl + x[r] - x[l]);
        } else {
            res = min(res, a_xr + x[r] - x[l]);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/algorithm/searching/knuth_morris_pratt.hpp>
using namespace std;
 
using ll = long long;
using boost::irange;
 
int main(){
 
    int N;
    string S;
    cin >> N >> S;
 
    int ans = 0;
    int index = 0;
 
    for(int i : irange(1,N-1)){

        auto it = boost::algorithm::knuth_morris_pratt_search(S.begin() + i, S.end(), S.begin()+index, S.begin() + i);
        if (it != S.end()){
            ans = i - index;
        }
        else{
            index++;
        }
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int main()
{
	int n;
	int a[105];
	scanf ("%d",&n);
	for (int i = 1 ; i <= n ;i++)
	 {
	 	scanf ("%d",&a[i]);
	 }

	 int m;
	 scanf ("%d",&m);
	 int b[105],c[105];
	
	for (int i = 1 ; i <= m ;i++)
	 {
	 	scanf ("%d%d",&b[i],&c[i]);
	 }
	 long long int sum = 0;
	for (int j = 1;j <= m ;j++)
	  {
	  	sum = 0;
	  	for (int i = 1 ; i<= n ;i++)
	    {
	  	 
	  	 {
	  	 	if (i == b[j])
	  	      sum +=c[j];
	  	    else
	  	     sum += a[i];
		 }
		 
	  	
	    }
	printf ("%lld\n",sum);
	  }
	 
return 0;
}

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

int main(){
  cin >> S;
  int N = S.size();
  int hug = 0;
  
for (int i = 0; i < N/2; i++){
  
  if (S.at(i) != S.at(N-1-i)){  
    char c = S.at(N-1-i);
    S.at(i) = c;
    hug++;
  }
    else hug = hug;

}
  
  cout << hug << endl;
  }

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
int n,m,i,c,d,a[200200];
long long x[2],r;
int main() {
  for (i=0; i<2; i++) x[i]=1;
  scanf("%d%d",&n,&m);
  for (i=0; i<n; i++) {
    scanf("%d",&a[i]);
    a[i]*=2;
  }
  for (i=0; i<m; i++) {
    scanf("%d",&a[n+i]);
    a[n+i]=a[n+i]*2+1;
  }
  n+=m;
  sort(a,a+n);
  for (i=n-1; i>=0; i--) {
    c=a[i]/2;
    d=a[i]%2;
    r+=x[d]*c;
    x[1-d]++;
  }
  printf("%lld\n",r);
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    vector<int> t(3);
    cin >> t[0] >> t[1] >> t[2];
    sort(t.begin(), t.end());
    cout << t[0] + t[1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair <int, int> pii;
bool scomp(const pii &a, const pii &b){
    return (a.second==b.second)? a.first<b.first: a.second<b.second; 
}

int main(){
    int n;
    cin >> n;
    vector<int> sum(100002, 0);
    vector<pii> fs(n);
    for(int i=0; i<n; i++){
        int a,b;
        cin >> a >> b;
        fs[i] = pii(a,b);
        sum[a]++;
        sum[b]--;
    }
    for(int i=0; i<100001; i++){
        sum[i+1] += sum[i];
    }
    int ans2 = *max_element(sum.begin(), sum.end());

    vector<pii> sc = fs;
    sort(fs.begin(), fs.end());
    sort(sc.begin(), sc.end(), scomp);
    int ans1 = 0;
    for(auto e: fs){
        int sub = n;
        sub -=  fs.end() -lower_bound(fs.begin(), fs.end(), pii(e.second, 0));
        sub -= lower_bound(sc.begin(), sc.end(), pii(0, e.first+1), scomp) -sc.begin();
        ans1 = max(ans1, sub);
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}


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

typedef long long ll;

int main() {
	ll K, A, B;
	cin >> K >> A >> B;

	if (B - A <= 2) {
		cout << K+1 << endl;
	}
	else {
		ll ans=0;
		K -= A-1;
		ll C = K/2;
		//cout << K <<" "<< C << endl;
		ans += A+C*(B-A);
		K -= C*2;
		ans += K;
		//cout << K << endl;
		cout << ans << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

bool bmap[2000][2000]  = {};
int  wcmap[2000][2000] = { 0 };
int  hcmap[2000][2000] = { 0 };

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int hmax, wmax;  cin >> hmax >> wmax;

	FOR_LT(h, 0, hmax) {
		FOR_LT(w, 0, wmax) {
			char c; cin >> c;
			if (c == '#') bmap[h][w] = false;
			else          bmap[h][w] = true;
		}
	}

	FOR_LT(h, 0, hmax) {
		int  w_s      = -1;
		bool is_clear = false;
		FOR_LT(w, 0, wmax) {
			if (bmap[h][w]) {
				if (!is_clear) {
					is_clear = true;
					w_s = w;
				}
			}
			else {
				if (is_clear) {
					int s = w - w_s;
					FOR_LT(i, w_s, w) {
						wcmap[h][i] = s;
					}
					is_clear = false;
				}
				wcmap[h][w] = 0;
			}
		}

		if (is_clear) {
			int s = wmax - w_s;
			FOR_LT(i, w_s, wmax) {
				wcmap[h][i] = s;
			}
		}
	}

	FOR_LT(w, 0, wmax) {
		int  h_s = -1;
		bool is_clear = false;
		FOR_LT(h, 0, hmax) {
			if (bmap[h][w]) {
				if (!is_clear) {
					is_clear = true;
					h_s = h;
				}
			}
			else {
				if (is_clear) {
					int s = h - h_s;
					FOR_LT(i, h_s, h) {
						hcmap[i][w] = s;
					}
					is_clear = false;
				}
				hcmap[h][w] = 0;
			}
		}

		if (is_clear) {
			int s = hmax - h_s;
			FOR_LT(i, h_s, hmax) {
				hcmap[i][w] = s;
			}
		}
	}

	int ans = 0;
	FOR_LT(h, 0, hmax) {
		FOR_LT(w, 0, wmax) {
			ans = max(ans, wcmap[h][w] + hcmap[h][w]);
		}
	}

	cout << (ans - 1) << endl;


	return 0;
}

Measured memory_bytes: 35456
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}
 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;
}

const ll N=5e5+5;

ll sp[N];

void sieve(){
  for(int i=2;i<N;i++)sp[i]=i;

    for(int i=2;i*i<N;i++){
      if(sp[i]==i){
      for(int j=i*i;j<N;j+=i){
        sp[j]=i;
      }
    }
}

}

ll fac[N],inv[N];

ll p=1e9+7;

void fill(){
  fac[0]=inv[0]=1;

  for(int i=1;i<N;i++){
    fac[i]=fac[i-1]*i%p;
    inv[i]=powM(fac[i],p-2,p);
  }
}

ll c(ll a,ll b,ll p){
if(a<b)return 0;

  return (fac[a]*inv[a-b]%p)*(inv[b])%p;
}


ll dp[3005][3005][2];

// p=998244353;

int main()
{ 

  IOS;



ll g=0;

ll n,s;
cin>>n>>s;

for(int i=0;i<n;i++){
  ll x;cin>>x;
  g=__gcd(g,abs(x-s));
}

cout<<g<<endl;

return 0;
 
}



Measured memory_bytes: 3664
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int [][]po=new int[n][2];
        int index=0;
        int []hh=new int[n];
        for(int i=0;i<n;i++){
            po[i][0]=sc.nextInt();
            po[i][1]=sc.nextInt();
            if((hh[i]=sc.nextInt())>0)index=i;
        }
    
        int x=0,y=0,h=0;
        Po:for(x=0;x<=100;x++){
            for(y=0;y<=100;y++){
                boolean b=true;
                h=hh[index]+Math.abs(x-po[index][0])+Math.abs(y-po[index][1]);
                for(int i=0;i<n;i++){
                    if(Math.max(0,h-(Math.abs(x-po[i][0])+Math.abs(y-po[i][1])))!=hh[i]){
                        b=false;
                        break;
                    }
                }
                if(b)break Po;
            }
        }
        System.out.println(x+" "+y+" "+h);
    }
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<int,int>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
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 vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<60
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 1000000007;

inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;
x=x*x%mod;n>>=1;}return res;}
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}


//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
   int N,Q;cin>>N>>Q;
   UnionFind U(N);
   rep(i,Q){
      int t,u,v;cin>>t>>u>>v;
      if(t==0){
         U.merge(u,v);
      }
      else{
         cout<<(int)U.issame(u,v)<<endl;
      }
   }
}

Measured memory_bytes: 3956
#include <stdio.h>
#define INF (1<<21)
#define MAX 105

int n,g[MAX][MAX];

void dijkstra(){
  int min,d[MAX],judge[MAX],i,u,v;
  for(i=0;i<n;i++){
    d[i]=INF;
    judge[i]=0;
  }
  d[0]=0;
  while(1){
    min=INF;
    u=-1;
    for(i=0;i<n;i++){
      if(min>d[i] && judge[i]!=1){
	u=i;min=d[i];
      }
    }
    if(u==-1) break;
    judge[u]=1;
    for(v=0;v<n;v++){
      if(judge[v]!=1 && g[u][v]!=INF){
	if(d[v]>d[u]+g[u][v]) d[v]=d[u]+g[u][v];
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
}

int main(){
  int u,k,i,j,v,c;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      g[i][j]=INF;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      g[u][v]=c;
    }
  }
  dijkstra();
  return 0;
}
		    



Measured memory_bytes: 1984
/*
        Author: Prokash
                CSE48, JU

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
    FAST;
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    if((a+b)<2*c)
    {
        cout<<a*x+b*y<<endl;
        return 0;
    }
    else

    {
        if(x>y)
        {
            if(2*c<a)
            {
                cout<<2*c*x<<endl;
                return 0;
            }
            else

            {
                cout<<2*c*y+a*(x-y)<<endl;
                return 0;
            }
        }
        else
        {
            if(2*c<b)
            {
                cout<<2*c*y<<endl;
                return 0;
            }
            else
            {
                cout<<2*c*x+b*(y-x)<<endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256