akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;

ll t1, t2, a1, a2, b1, b2;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	a1 *= t1, a2 *= t2, b1 *= t1, b2 *= t2;
	if (a1 + a2 == b1 + b2) {
		cout << "infinity";
		return 0;
	} else if ((a1 > b1 && a2 > b2) || (a1 < b1 && a2 < b2)) {
		cout << 0;
		return 0;
	} else { 
		if (llabs(a2 - b2) < llabs(a1 - b1)) {
			cout << "0";
			return 0;
		}
		
		ll dist = llabs(a1 - b1);
		ll gain = llabs(llabs(a1 - b1) - llabs(a2 - b2));
		ll ans = ceil((long double)dist / gain) * 2ll;
		if (dist % gain) --ans;
		cout << ans;
	}
}


Measured memory_bytes: 3696
import sys
input = sys.stdin.readline


class BIT:
    def __init__(self, size):
        self.bit = [0]*(size+1)
        self.size = size

    def sum(self, i):
        i += 1
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.bit[i] += x
            i += i & -i


N = int(input())
S = list(input().rstrip())
bits = [BIT(N) for _ in range(26)]
for i in range(N):
    bits[ord(S[i])-ord('a')].add(i, 1)
Q = int(input())
for _ in range(Q):
    t, x, y = input().split()
    if t == '1':
        i = int(x) - 1
        c = y
        bits[ord(S[i])-ord('a')].add(i, -1)
        bits[ord(c)-ord('a')].add(i, 1)
        S[i] = c
    else:
        l = int(x) - 1
        r = int(y) - 1
        ans = 0
        for i in range(26):
            cnt = bits[i].sum(r) - (bits[i].sum(l-1) if l > 0 else 0)
            if cnt > 0:
                ans += 1
        print(ans)


Measured memory_bytes: 166684
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		struct Restaurant {
			public string Name { get; set; }
			public int Rate { get; set; }
			public int ID{ get; set; }
		}
		public void Solve(ConsoleInput cin) {
			var N = cin.ReadInt;
			var RS = new Restaurant[N];
			for(int i = 0; i<N; i++) {
				var query = cin.ReadStrArray(2);
				RS[i]=new Restaurant { Name=query[0], Rate=int.Parse(query[1]), ID=i+1 };
			}
			var Res = RS.OrderBy(x => x.Name).ThenByDescending(x => x.Rate);
			Console.WriteLine(Res.Select(x => x.ID).Join("\n"));
		}
	}
	static class ExtendClass {
		public static void Swap<T>(this T[] A, int x, int y) {
			var tmp = A[x];
			A[x]=A[y];
			A[y]=tmp;
		}
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		public static IEnumerable<int> Indices<T>(this T[] X) => Enumerable.Range(0, X.Length);
		public static IEnumerable<int> Indices<T>(this T[,] X, int dim)
			=> Enumerable.Range(0, X.GetLength(dim));
		public static string Join<T>(this T[,] X, string separatorD2 = ",", string separatorD1 = "\n")
			=> X.Indices(0).Select(
				i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2)
			).Join(separatorD1);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}

}

Measured memory_bytes: 12128
#include <bits/stdc++.h>
using namespace std;
 
 
#define ll long long
#define MOD 1000000007
#define pll             pair<ll,ll>
#define pii             pair<int,int> 
#define mp(a,b)         make_pair(a,b)
#define pb 				push_back
#define vi				vector<int>
#define vl 				vector<long long>
#define vb 				vector<bool>
#define printv(v)		for(auto x : v) cout<<x<<' ';br;
#define FOR(i,a,b) 		for(ll i = a; i <= b ; i++)
#define forn(i,n) 		for(ll i = 0 ; i < n; i++)
#define br 				cout<<endl;
#define testc()			ll t;cin>>t;while(t--)
 
#define fast 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF				INT_MAX
#define INFL			LLONG_MAX
#define max1(x,y) (x)>(y)?(x):(y)
#define ss second
#define ff first
#define MAXN 1000000001

int main(){
    fast
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    forn(i,n)
    cin>>arr[i];
    ll dp[n];
    forn(i,n)
    dp[i]=1e10+5;
    dp[0]=0;
    FOR(i,0,n-1){
        FOR(j,i+1,i+k)
        if(j<n)
        dp[j]=min(dp[j],dp[i]+abs(arr[i]-arr[j]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
# 右と下に移動する場合は絶対に最短経路になるので、最短経路を出してそれ以外に#があったらアウト、の方針で
def end_impossible():
    print("Impossible")
    exit()


H, W = map(int, input().split())
A = [input() for _ in range(H)]
seen = []

if A[0][0] == ".":
    end_impossible()

seen.append([0, 0])
h, w = 0, 0

while h != H - 1 or w != W - 1:
    if h < H - 1 and A[h + 1][w] == "#":
        h += 1
    elif w < W - 1 and A[h][w + 1] == "#":
        w += 1
    else:
        end_impossible()
    seen.append([h, w])

for i in range(H):
    for j in range(W):
        if A[i][j] == "#" and [i, j] not in seen:
            end_impossible()

print("Possible")


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <map>
#include <vector>

using namespace std;

class Dice {
public:
    map<string, int> pos;

    Dice() {
        reset();
    };

    void reset() {
        Dice::pos = {{"Top", 1}, {"North", 5}, {"East", 3}, {"South", 2}, {"West", 4}, {"Bottom", 6}};
    }

    int top() {
        return pos["Top"];
    }

    void rotate(const vector<string> &v) {
        int tmp = pos[v[0]];
        for (int i=0; i<(int)v.size() - 1; ++i) pos[v[i]] = pos[v[i + 1]];
        pos[v[(int)v.size() - 1]] = tmp;
    }

    void go(string di) {
        if (di == "North") rotate({"Top", "South", "Bottom", "North"});
        else if (di == "East") rotate({"Top", "West", "Bottom", "East"});
        else if (di == "West") rotate({"Top", "East", "Bottom", "West"});
        else if (di == "South") rotate({"Top", "North", "Bottom", "South"});
        else if (di == "Right") rotate({"South", "East", "North", "West"});
        else if (di == "Left") rotate({"South", "West", "North", "East"});
    }
};

int main() {
    auto dice = Dice();
    int n;
    string di;
    while (cin >> n && n != 0) {
        dice.reset();
        int sum = 1;
        while (n --) {
            cin >> di;
            dice.go(di);
            sum += dice.top();
        }
        cout << sum << endl;
    }
    return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	map<string, ll> mp;
	rep(i, n){
		string s; cin >>s; 
		sort(all(s));
		mp[s]++;
	}
	ll ans = 0;
	for(auto& x: mp){
		ans += x.second * (x.second -1) / 2;
	}
	cout <<ans <<"\n";
	return 0;
	
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var < (end); var++)
#define RFOR(var, begin, end) for (int var = (begin) - 1; var >= (end); var--)
#define REP(var, length) FOR(var, 0, length)
#define RREP(var, length) RFOR(var, length, 0)
#define SORT(vector) sort(vector.begin(), vector.end())

const ll MOD = 1e9 + 7;

struct CMod {
    vector<ll> fact, inv, finv;

    CMod(int n) : fact(n + 1), inv(n + 1), finv(n + 1) {
      fact[0] = 1;
      fact[1] = 1;
      inv[0] = 1;
      inv[1] = 1;
      finv[0] = 1;
      finv[1] = 1;

      FOR(i, 2, n + 1) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
      }
    }

    ll P(int m, int n) {
      if (m < n) return 0;
      return fact[m] * finv[m - n] % MOD;
    }

    ll C(int m, int n) {
      if (m < n) return 0;
      return fact[m] * (finv[n] * finv[m - n] % MOD) % MOD;
    }

};

int k;
vector<vector<int>> e;
vector<int> done;
ll ans;
CMod *cm;

void DFS(int n) {
  int cnt = 0;
  done[n] = 1;
  for (auto v : e[n]) {
    if (done[v]) continue;
    DFS(v);
    cnt++;
  }
  ans *= cm->P(k - 2, cnt);
  ans %= MOD;
}

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n >> k;
  int a, b;

  e = vector<vector<int>>(n);
  done = vector<int>(n, 0);
  CMod x(k);
  cm = &x;

  REP(i, n - 1) {
    cin >> a >> b;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }

  done[0] = 1;
  ans = cm->P(k, e[0].size() + 1);
  for (auto v : e[0]) {
    DFS(v);
  }
  cout << ans << endl;

}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


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

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

    string s1, s2;
    s1.push_back(s[0]);
    s1.push_back(s[1]);
    s2.push_back(s[2]);
    s2.push_back(s[3]);

    int flagM1=1, flagM2=1;
    int s_to_i1, s_to_i2;
    s_to_i1 = atoi(s1.c_str());
    s_to_i2 = atoi(s2.c_str());

    if(s_to_i1 > 12 || s_to_i1 < 1){
        flagM1 = 0;
    }
    if(s_to_i2 > 12 || s_to_i2 < 1){
        flagM2 = 0;
    }


    if(flagM1 == 0 && flagM2 == 0){
        cout << "NA" << endl;
    }
    if(flagM1 == 0 && flagM2 == 1){
        cout << "YYMM" << endl;
    }
    if(flagM1 == 1 && flagM2 == 0){
        cout << "MMYY" << endl;
    }
    if(flagM1 == 1 && flagM2 == 1){
        cout << "AMBIGUOUS" << endl;
    }



    return 0;
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,n;
    cin >> n;
    for(i=1;i<=sqrt(n);i++)
    {
        if(n%i == 0  &&  i <= 9  &&  (n/i) <= 9)
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r,int c){
  stack<int> S;
  S.push(r);
  color[r] = c;
  while(!S.empty()){
    int u = S.top(); S.pop();
    for(int i=0;i<G[u].size();i++){
      int v = G[u][i];
      if(color[v] == NIL){
	color[v] = c;
	S.push(v);
      }
    }
  }
}

void assignColor(){
  int id = 1;
  for(int i=0;i<n;i++) color[i] = NIL;
  for(int u=0;u<n;u++){
    if(color[u] == NIL) dfs(u,id++);
  }
}

int main(){
  int s,t,m,q;

  cin >> n >> m;

  for(int i=0;i<m;i++){
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin >> q;

  for(int i=0;i<q;i++){
    cin >> s >> t;
    if(color[s] == color[t]){
      cout << "yes" << endl;
    }else{
      cout << "no" << endl;
    }
  }

  return 0;
}



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

int main(){
	int n, a, b, c, d;
	while(cin >> n){
		int count = 0;
		if(n > 36){
			cout << 0 << endl;
		}
		else{
			for(a = 0; a <= 9; a++){
				for(b = 0; b <= 9; b++){
					for(c = 0; c <= 9; c++){
						for(d = 0; d <= 9; d++){
							if((a + b + c + d) == n) count++;
						}
					}
				}
			}
			cout << count << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
n, a, b = map(int, input().split())
X = list(map(int, input().split()))
ans = 0
m = b // a
for i in range(n-1):
  d = X[i+1] - X[i]
  if d > m:
    ans += b
  else:
    ans += a*d
print(ans)

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

int main() {
    string s;
    cin >> s;
    int m = 0;
    for (int i = 0; i < s.size(); i++) {
        if (i % 2 == 0 && s[i] == 'L') m++;
        if (i % 2 == 1 && s[i] == 'R') m++;
    }
    if (m == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int a,b;
    cin >>a>>b;
    int x;
    x=(a+b)/2;
    if((a+b)%2==0){
        cout << abs(x) << endl;
    }
    else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define ceil(a,b) (a+b-1)/b
#define endl "\n"

#define oa(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define o1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define o2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define o3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define o4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

 const int N=100005;
 const int inf=1e18;
 const double eps=1e-9;
int pow1(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int k;
    cin>>k;
    int s=0;
    // int c=0;
    int g;
    for(int x=1;x<=k;x++){
        for(int y=1;y<=k;y++){
              
            for(int z=1;z<=k;z++){
               g=__gcd(x,y);
                g=__gcd(g,z);
                if(z==1||x==1||y==1){
                    g=1;
                }
                s+=g;
                
                // o3(x,y,z);
                // c++;
            }
        }
    }
    // cout<<c<<endl;
    cout<<s;








	
return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
using namespace std;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> data;
    for (ll i=0; i<n; i++){
        ll a;
        cin>>a;
        data.push_back(a);
    }
    sort(data.begin(), data.end());
    if (n<=k) cout<<"0"<<endl;
    else{
        ll count=0;
        for (ll i=0; i<n-k; i++) count+=data[i];
        cout<<count<<endl;
    }
}

Measured memory_bytes: 2420
#include <iostream>
#include <algorithm>

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)

using namespace std;


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0;i < s.size();i++){
        s[i] = s[i] + n;
        if(s[i] > 'Z')
            s[i] = s[i] - (char)26;
    }
    cout << s << endl;
    return 0;
}




Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
vector<int> yp[100001];

int main(int argc, char const* argv[])
{
  int n, m;
  cin >> n >> m;
  vector<int> p, y;
  map<P, int> mp;
  for(int i = 0; i < m; i++){
    int pp;
    ll yy;
    cin >> pp >> yy;
    pp--;
    p.pb(pp);
    yp[pp].pb(yy);
    y.pb(yy);
  }
  for(int i = 0; i < n; i++){
    if(yp[i].size() == 0)continue;
    sort(yp[i].begin(), yp[i].end());
    for(int j = 0; j < yp[i].size(); j++){
      mp[mk(i, yp[i][j])] = j;
    }
  }
  for(int i = 0; i < m; i++){
    printf("%06d", p[i] + 1);
    printf("%06d\n", mp[mk(p[i], y[i])] + 1);
  }
	return 0;
}


Measured memory_bytes: 13936
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int *place;
  int k;
    place = new int[5];
    for(int i=0;i<5;i++)
    {
        scanf("%d",&place[i]);
    }
  scanf("%d",&k);
    if(k >= place[4] - place[0])
    {
      cout << "Yay!" << endl;
    }
  else
    {
    cout << ":(" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


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

int bfs(const vector<string> &v,int x,int y){
    int H = v.size();
    int W = v[0].size();
    vector<vector<int>> dist(H,vector<int>(W,-1));
    queue<pair<int,int>> que;

    int res = 0;
    que.push({x,y});
    dist[x][y] = 0;
    while(!que.empty()){
        int x = que.front().first, y = que.front().second;
        res = max(res,dist[x][y]);
        que.pop();
        for(int dir=0; dir<4;dir++){
            int nx = x + dx[dir], ny = y + dy[dir];
            if(nx<0 || nx >= H || ny < 0 || ny >= W) continue;
            if(v[nx][ny] == '#') continue;
            if(dist[nx][ny] == -1){
                dist[nx][ny] = dist[x][y] + 1;
                que.push({nx,ny});
            }
        }
    }
    return res;
}


int main(){
    FIN;
    int H,W;
    cin >> H >> W;
    vector<string> v(H);
    for(int i=0;i<H;i++) cin >> v[i];

    int ans = 0;
    for(int x=0;x<H;x++){
        for(int y=0;y<W;y++){
            if(v[x][y] == '#') continue;
            ans = max(ans,bfs(v,x,y));
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W));
  rep(i, H) {
    rep(j, W) {
      cin >> A[i][j];
    }
  }
  vector<vector<int>> B(H, vector<int>(W));
  rep(i, H) {
    rep(j, W) {
      cin >> B[i][j];
    }
  }

  vector<vector<int>> diff(H, vector<int>(W));
  rep(i, H) {
    rep(j, W) {
      diff[i][j] = abs(A[i][j] - B[i][j]);
    }
  }

  int mx = 80 * (80 + 80);
  int nm = mx * 2 + 1;
  bool dp_[H][W][nm];
  fill((bool*)dp_, (bool*)(dp_ + H), false);

  bool* dp[H][W];
  rep(i, H) {
    rep(j, W) {
      dp[i][j] = &(dp_[i][j][mx]);
    }
  }

  dp[0][0][diff[0][0]] = true;
  dp[0][0][-diff[0][0]] = true;

  rep(i, H) {
    rep(j, W) {
      repp(k, -mx, mx) {
        if (dp[i][j][k] == false)
          continue;

        if (i + 1 < H) {
          dp[i + 1][j][k + diff[i + 1][j]] = true;
          dp[i + 1][j][k - diff[i + 1][j]] = true;
        }


        if (j + 1 < W) {
          dp[i][j + 1][k + diff[i][j + 1]] = true;
          dp[i][j + 1][k - diff[i][j + 1]] = true;
        }
      }
    }
  }

  int ans = INF;
  repp(k, -mx, mx) {
    if (!dp[H - 1][W - 1][k])
      continue;
    chmin(ans, abs(k));
  }
  cout << ans << endl;
}

Measured memory_bytes: 160384
#include<stdio.h>
int main(){
    int a,b;
    scanf("%d  %d",&a , &b);
    if(a>b){
        printf("a > b\n");
    }
    else if(a<b){
        printf("a < b\n");
    }
    else{
        printf("a == b\n");
    }
    return 0;
}
 

Measured memory_bytes: 1800
//AND BAND KA TOLA JO MERA CODE DEKHRA WO BHEN KA ....
//------------------------------------------Template------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define lp(i,a,b) for(ll i=a;i<b;i++)
#define rlp(i,a,b) for(ll i=b;i>=a;i--)
#define TEZI_BOLTEY ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 1e9
#define pb push_back 
#define mp make_pair 
#define endl "\n"
ll nCr(ll n, ll k) {double res = 1;lp(i,1,k+1){res = res * (n - k + i) / i;}return (int)(res + 0.01);}
//---------------------------------------------------------------------------------------------------
//---------------------------------<<< DRAGON SIN MELIODAS >>>---------------------------------------
//---------------------------------------------------------------------------------------------------
int32_t main()
{
	TEZI_BOLTEY
	ll t;
	cin >> t;
	string ans="";
	string s="ACL";
	lp(i,0,t)
	{
		ans+=s;
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 3584
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function (chunk) {
	var tmp,i,j;
	var e = chunk.split(' ');
	b = parseInt(e[0],10);
	c = parseInt(e[1],10);
	d = parseInt(e[2],10);
	a = [b,c,d];
	a.sort();
	console.log(a[0]+' '+a[1]+' '+a[2]);
});

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

int main(){
  char s[100];
  char *s1="Sunny";
  char *s2="Cloudy";
  char *s3="Rainy";
  
  scanf("%s",s);
  if(strcmp(s,s1)==0) puts("Cloudy");
  if(strcmp(s,s2)==0) puts("Rainy");
  if(strcmp(s,s3)==0) puts("Sunny");
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define FF first
#define SS second
#define pii pair<int,int>
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(x) (int)x.size()
#define mp make_pair
#define Mod 1000000007
typedef long long int ll;

vector<int> dp;
vector<bool> vis;
vector<vector<int>> adj; 

void dfs(int node){
	vis[node] = true;
	for(auto it = adj[node].begin(); it != adj[node].end(); ++it){
		if(!vis[*it])
			dfs(*it);

		dp[node] = max(dp[node], dp[*it]+1);
	}
}

int main(){

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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// #endif

	//dp[i] ->  store the maximum length of path starting from i

	int n, m, i, ans = -1, u, v;
	cin >> n >> m;
	
	adj.assign(n+1, vector<int>());
	for(i = 0; i < m; i++){
		cin >> u >> v;
		adj[u].eb(v);
	}

	dp.assign(n+1, 0);
	vis.assign(n+1, false);
	for(i = 1; i <= n; i++)
		if(!vis[i])
			dfs(i);

	cout<<*max_element(dp.begin(), dp.end());
}  

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define il inline
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define rep0(i, n) for(int i = 0; i < (n); i ++)
#define per0(i, n) for(int i = (n) - 1; i >= 0; i --)
#define ept 1e-9
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define ALL(x) (x).begin(), (x).end()
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int N = 300100;
int sum[2][N], n;
char ch[N];
int main()
{
	n = read();
    scanf("%s", ch + 1);
    rep(i, 1, n)
    {
        sum[0][i] = sum[0][i - 1] + (ch[i] == 'E');
        sum[1][i] = sum[1][i - 1] + (ch[i] == 'W');
    }
    int ans = n + 1;
    rep(i, 1, n)
    	ans = min(ans, sum[1][i - 1] + sum[0][n] - sum[0][i]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>

using namespace std;

int main() {
    int n, x, y, b, p, c1, c2;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x >> y >> b >> p;
        c1 = x * b + y * p;
        c2 = (x * max(b, 5) + y * max(p, 2)) * 4 / 5;
        cout << min(c1, c2) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, l, t, pos[100007], cnt;
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
signed main()
{
	n = read();
	l = read();
	t = read();
	for (int i = 1; i <= n; i++)
	{
		int a = read(), b = read();
		pos[i] = (a + ((b == 1 ? 1 : -1) * (t % l) + l) % l) % l;
		if (b == 1)cnt += (a + t) / l;
		else cnt -= (t - a + l - 1) / l;
	}
	sort(pos + 1, pos + n + 1);
	cnt = (cnt % n + n) % n;
	for (int i = cnt + 1; i <= n; i++)
		printf("%lld\n", pos[i]);
	for (int i = 1; i <= cnt; i++)
		printf("%lld\n", pos[i]);
	return 0;
}

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

using namespace std;
using ll = long long;
#define mod 1000000007
ll mypower(ll a, ll b, ll p)
{
    ll ans = 1;
    a = a%p;
    while(b)
    {
        if(b%2)
            ans = ans*a % p;
        b=b/2;
        a = a*a % p;
    }
    return ans;
}
int main() {
    ll x;
    cin >> x;
    ll i = 0, j;
    int ok = 0;
    while(i*i*i*i*i < x)
    {
        ll val = x - i*i*i*i*i;
        j = 0;
        while(j*j*j*j*j < val)
            j++;
        if(j*j*j*j*j == val)
        {
            ok = 1;
            break;
        }
        i++;
    }
    if(ok)
    {
        cout << i << " " << -j << '\n'; 
    }
    else // Now i*i*i*i*i > X
    {
        ll max = 1e18;
        while(i*i*i*i*i < max)
        {
            ll val = i*i*i*i*i - x;
            j = 0;
            while(j*j*j*j*j < val)
                j++;
            if(j*j*j*j*j == val)
                break;
            i++;
        }
        cout << i << " " << j << '\n';
    }
}

Measured memory_bytes: 3632
N,s = input().split()
S = int(s)
a = []
for i in range(int(N)):
    a.append(int(input()))

a.sort()

mindiff = 1000000000

for i in range(int(N)-(S - 1)):
    v = a[i+S-1]-a[i]

    if mindiff > v: mindiff = v

print(mindiff)



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    string S; cin >> S;
    int count = 0;
    REP(i,S.size()){
        if(S[i] == '0'){
            count ++;
        }
    }
    cout << 2*min(count, (int)S.size()-count) << endl;

    return 0;
}

Measured memory_bytes: 3728
#include <stdio.h>
 
int main(){
	long long int x, i=0;
	long long int m=100;
	
	
	scanf("%lld", &x);
	
	while(m<x){
		m+=m/100;
		i++;
	}
	
	printf("%lld", i);
	
	return 0;
}

Measured memory_bytes: 2104
Scanf.scanf "%d" (fun n ->
    let dump k =
        let a = Array.make k [] in
        let rec loop_i i cur =
            let rec loop_j j cur =
                if j >= k then cur else (
                    a.(i) <- cur :: a.(i);
                    a.(j) <- cur :: a.(j);
                    loop_j (j + 1) (cur + 1)
                )
            in
            if i = k then () else
                loop_i (i + 1) (loop_j (i + 1) cur)
        in
        loop_i 0 1;
        Array.iter (fun l ->
            let b = Array.of_list l in
            Printf.printf "%d" (Array.length b);
            Array.iter (Printf.printf " %d") b;
            print_newline ()) a
    in

    let rec loop k =
        let k2 = k * (k - 1) / 2 in
        if k2 = n then k else
            if k2 < n then loop (k + 1) else (-1)
    in
    let k = loop 2 in
    if k < 0 then print_endline "No" else (
        Printf.printf "Yes\n%d\n" k;
        dump k
    )
)

Measured memory_bytes: 12184
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

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

    string S;
    cin >> S;
    int K;
    cin >> K;
    const int N = sz(S);
    using P = pair<string, int>;
    priority_queue<P,vector<P>,greater<P> > T;
    rep(i, N) {
        string s;
        s += S[i];
        T.push(mp(s, i));
    }

    string re = "";
    rep(i, K) {
        auto p = T.top(); T.pop();
        int j = p.second + sz(p.first);
        if (re == p.first) {
            --i;
        }
        re = p.first;
        if (j < N) {
            p.first += S[j];
            T.push(p);
        }
    }
    cout << re << endl;
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    ll n, x;
    cin >> n >> x;
    // なぜ1つ多く作るのか？？？
    vector<ll> a(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] + a[i-1] <= x) continue;
        ans += (a[i] + a[i-1] - x);
        a[i] -= (a[i] + a[i-1] - x);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>


int main(){
	int n;
	int id[4000],cid;
	long long int price,num,sale[4000];
	bool f;
	int i,j,idcount;
	while(scanf("%d",&n),n){

		f=true;
		idcount=0;

		for(i=0;i<n;i++){
			scanf("%d %lld %lld",&cid,&price,&num);

			for(j=0;j<idcount;j++){
				if(id[j]==cid){
					sale[j]=sale[j]+price*num;
				}
			}

			if(j==idcount){
				id[idcount]=cid;
				sale[idcount]=price*num;
				idcount++;
			}

		}



		for(i=0;i<idcount;i++){
			if(sale[i]>=1000000){
				printf("%d\n",id[i]);
				f=false;
			}
		}
		if(f!=false)printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 0
from math import sqrt, ceil

N = int(input())
sq = ceil(sqrt(N))
min_st = N-1

for i in range(2, sq+1):
    if ((N % i) == 0):        
        if (i + N//i - 2 < min_st):
            min_st = i + N//i-2

print(min_st)


Measured memory_bytes: 40172
#include<bits/stdc++.h>
using namespace std;
const int N=505,dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int n,a[N][N],dp[N][N],x[N*N],y[N*N],qx[N*N],qy[N*N],v[N][N],ans;
void bfs(int bx,int by)
{
	dp[bx][by]--;
	int b=0,e=1;
	qx[0]=bx,qy[0]=by;
	while(b<e)
	{
		int kx=qx[b],ky=qy[b];
		b++;
		for(int i=0;i<4;i++)
		{
			int x=kx+dx[i],y=ky+dy[i];
			if(x<1||x>n||y<1||y>n||dp[x][y]<=dp[kx][ky]+v[x][y])
				continue;
			dp[x][y]=dp[kx][ky]+v[x][y];
			qx[e]=x,qy[e]=y;
			e++;
		}
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n*n;i++)
	{
		int p;
		scanf("%d",&p);
		x[i]=(p-1)/n+1;
		y[i]=(p-1)%n+1;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			dp[i][j]=min(min(i,n-i+1),min(j,n-j+1)),v[i][j]=1;
	for(int i=1;i<=n*n;i++)
	{
		ans+=dp[x[i]][y[i]]-1;
		v[x[i]][y[i]]=0;
		bfs(x[i],y[i]);
		//printf("%d %d %d\n",x[i],y[i],ans);
	}
	printf("%d\n",ans);
	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

struct edge{
    int from,to,cost;
};

void solve(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> d(n,vector<int>(n,inf));
    vector<edge> es;
    rep(i,0,n) d[i][i]=0;
    rep(i,0,m){
        int a,b,c;
        cin >> a >> b >> c;
        --a;
        --b;
        d[a][b]=d[b][a]=c;
        es.push_back({a,b,c});
    }
    rep(k,0,n){
        rep(i,0,n){
            rep(j,0,n){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    int ans=m;
    for(edge &e:es){
        bool f=false;
        rep(i,0,n){
            rep(j,0,n){
                if(d[i][j]==d[i][e.from]+e.cost+d[e.to][j]){
                    f=true;
                    break;
                }
                if(f) break;
            }
            if(f) break;
        }
        if(f) --ans;
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 384
//author: zekigurbuz (Zeki Gurbuz) 2019

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef queue<int> qi;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, vi> mvi;
typedef map<int, vpii> mvpii;
typedef priority_queue<int> pqi;
typedef set<int> si;

#define int ll
#define double ld
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rsz resize
#define forn(a,b) for(int a=0;a<b;++a)
#define rep(a,b,c) for(int a=b;a<c;++a)
#define all(x) begin(x), end(x)

const ld PI = 4*atan((ld)1);
const int MOD = 1000000007; //998244353
const ll INF = 1e18;
const int N = 200005;

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

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

signed main() {ios_base::sync_with_stdio(0);cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	int c = gcd(a,b);
	mii m;
	for (int i = 2; i * i <= c; i++) {
		while (c % i == 0) {
			m[i]++;
			c /= i;
		}
	}
	if (c != 1) m[c]++;
	cout << m.size() + 1 << endl;
	
return 0;}


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

int main(){
  string s;
  cin >> s;
  int zero=0, one=0;
  for(int i=0;i<s.length(); i++){
    if(s.at(i) == '0'){
      zero++;
    }else{
      one++;
    }
  }
  cout << min(zero,one)*2 << endl;
  return 0;
}


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

#define ll long long
#define ull unsigned long long

int main(void) {
    ll N, K;
    ll c = 0;
    map<ll, ll> m;
    cin >> N >> K;
    for(ll i = 0;i < N;i++) {
        ll temp;
        cin >> temp;
        m[temp] += 1;
    }
    if(m.size() <= K) {
        cout << 0 << endl;
    } else {
        ll sum = 0;
        vector<ll> l;
        for(auto &it: m) l.push_back(it.second);
        sort(l.begin(), l.end());
        for(ll i = 0;i < m.size() - K;i++) {
            sum += l[i];
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 14964
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        if(r<1200) System.out.println("ABC");
        else if(r<2800) System.out.println("ARC");
        else System.out.println("AGC");
    }
}


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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = (ll) 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 300005;


int main() {
    FAST
   int n;
    cin>>n;
    pair<int,int>p[n];
    for(int i=0;i<n;i++)
        cin>>p[i].first>>p[i].second;
    int c=0;
    for(int i=0;i<n;i++){
        if(p[i].first==p[i].second)
            c++;
        else{
            if(c>=3)
                return cout<<"Yes"<<endl,0;
            else{
              c=0;
            }
        }

    }
    if(c>=3)
        cout<<"Yes"<<endl;
    else{
        cout<<"No"<<endl;
    }



    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;

int main(void) {
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;

    ll u = min({q * 4, h * 2, s});

    if (n == 1) {
        cout << u << endl;
    }
    else {
        if (u * 2 <= d) {
            cout << n * u << endl;
        }
        else {
            if (n % 2 == 0) cout << (n / 2) * d << endl;
            else cout << (n / 2) * d + u << endl;
        }
    }
    
    return 0;
}

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

int main() {
	int h, w,number;
	string s;
	char ans;
	
	cin >> h >> w;
	for (int j = 0; j < h; j++) {
		for (char a = 'A'; a < 65 + w; a++) {
			cin >> s;
			if (s == "snuke") {
				ans = a;
				number = j+1;
			}
		}
	}
	cout << ans << number << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100;

bool all_zero(ll h[], ll N){
    rep(i, N) if(h[i] != 0) return false;
    return true;
}

ll where_is_zero(vector<ll>& loc, ll h[], ll N){
    ll cnt = 1;
    loc.push_back(-1);
    rep(i, N) if(h[i] == 0) {loc.push_back(i); cnt ++;}
    loc.push_back(N);
    return cnt;
}

int main(void){
    ll N;
    ll h[MAX_N];
    ll answer = 0;

    cin >> N;
    rep(i, N) cin >> h[i];

    while(!all_zero(h, N)){
        vector<ll> loc_zero;
        ll cnt = where_is_zero(loc_zero, h, N);
        rep(i, cnt) {
            if (loc_zero[i] + 1 != loc_zero[i + 1]) answer ++;
            For(j, loc_zero[i] + 1, loc_zero[i + 1]) h[j] --;
        }
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1000000000000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair

int x,a, b;

int main(){

cin >> x >> a >> b;
if(abs(x-a)>=abs(x-b))cout <<"B";
else cout << "A";



return 0;}


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

int main(){
  int n,m;

  while(1){
    
    int sum1=0;
    int sum2=0;
    
    cin >> n >> m;
    if(n + m == 0) break;

    int a[n],b[m];
    for(int i=0;i < n;i++){
      cin >> a[i];
      sum1 += a[i];
    }
    for(int i=0;i < m;i++){
      cin >> b[i];
      sum2 += b[i];
    }
    
    int card[2]={};
    int mini=201;
    int flag=0;
    
    for(int i=0;i < n;i++)
      {
	for(int j=0;j < m;j++){
	  
	  if( (sum1-a[i]+b[j]) == (sum2-b[j]+a[i]) && (a[i]+b[j]) < mini)
	    {
	      mini = a[i]+b[j];
	      card[0] = mini - b[j];
	      card[1] = mini - a[i];
	      flag = 1;
	    }
	}
      }
    if(flag == 1)
      {
	cout << card[0] << " " << card[1] << endl;
      }
    else
      {
	cout << -1 << endl;
      }
  }
  return 0;
}



Measured memory_bytes: 2988
dice1=gets.chomp.split(" ").map(&:to_i)
dice2=gets.chomp.split(" ").map(&:to_i)

[
    [0,1,2,3,4,5],[0,3,1,4,2,5],[0,4,3,2,1,5],[0,2,4,1,3,5],
    [1,5,2,3,0,4],[1,3,5,0,2,4],[1,0,3,2,5,4],[1,2,0,5,3,4],
    [2,5,4,1,0,3],[2,1,5,0,4,3],[2,0,1,4,5,3],[2,4,0,5,1,3],
    [3,5,1,4,0,2],[3,4,5,0,1,2],[3,0,4,1,5,2],[3,1,0,5,4,2],
    [4,5,3,2,0,1],[4,2,5,0,3,1],[4,0,2,3,5,1],[4,3,0,5,2,1],
    [5,4,2,3,1,0],[5,3,4,1,2,0],[5,1,3,2,4,0],[5,2,1,4,3,0]
].each do |pattern|
    if pattern.map {|i| dice1[i] } == dice2
        puts "Yes"
        exit
    end
end

puts "No"


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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long now = 0, ans = 1e18;
  for (int i = 1; i < n; i++) {
    now += a[i - 1];
    ans = min(ans, abs(now - (sum - now)));
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>                                             
#include <vector>                                               
using namespace std;                                            
                                                                
int main() {                                                    
  int n, m;                                                     
  while (true) {                                                
    cin >> n;                                                   
    if (n==0) {                                                 
      break;                                                    
    }                                                           
    vector<char> from(n);                                       
    vector<char> to(n);                                         
    for (int i=0; i<n; i++) {                                   
      cin >> from[i] >> to[i];                                  
    }                                                           
    cin >> m;                                                   
    vector<char> v(m);                                          
    for (int i=0; i<m; i++) {                                   
      cin >> v[i];                                              
      for (int j=0; j<n; j++) {                                 
        if (v[i]==from[j]) {                                    
          v[i] = to[j];                                         
          break;                                                
        }                                                       
      }                                                         
    }                                                           
    for (int i=0; i<m; i++) {                                   
      cout << v[i];                                             
    }                                                           
    cout << endl;                                               
  }                                                             
  return 0;                                                     
}                                    

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

string s;

void go()
{
	int x = 0;
	int d = 1;

	while(true)
	{
		if (x < 0 || x >= SZ(s)) break;

		if (s[x] == 'B')
		{
			s[x] = 'A';
			x += d;
			continue;
		}

		if (s[x] == 'A')
		{
			s[x] = 'B';
			d *= -1;
			x += d;
		}
	}
}

string gen(string s, int k)
{
	VI a;
	FOR (i, 0, SZ(s))
	{
		a.PB(s[i] == 'A');
	}

	int ind = 0;
	int cnt = 0;

	while(k > 0)
	{
		if (ind >= SZ(a))
		{
			break;
		}
		k--;
		if ((a[ind] ^ cnt) == 1)
		{
			a[ind]^= 1;
			continue;
		}

		ind++;
		cnt ^= 1;
	}

	string res;
	FOR (i, ind, SZ(a))
	{
		res += "BA"[a[i] ^ cnt];
	}

	int left = SZ(a) - SZ(res);

	if (left & 1) res += 'A', left--;

	FOR (i, 0, left/2) res += "BA";

	if ((k & 1) && (SZ(a) & 1))
	{
		if (res[0] == 'A') res[0] = 'B';
		else res[0] = 'A';
	}

	return res;

}

int main()
{
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false); cin.tie(0);

	int n, k;
	cin>>n>>k;
	string s;
	cin>>s;

	cout<<gen(s, k)<<endl;


	/*s = "BAAABBBABBBAAB";
	s = "BBAABAABBABABAABAAAAABABBBABBAAAB";

s="";
	int len = 47;
	FOR (i, 0, len)
	{
		s += "AB"[rand() % 2];
	}

	//s = "BABB";

	string ss = s;

	int k = 4002;

	cout<<s<<endl;
	FOR (it, 0, k)
	{
		go();
		cout<<s<<endl;
	}
	cout<<gen(ss, k)<<endl;


	if (gen(ss, k) != s) throw -1;*/

}


Measured memory_bytes: 1936