akhauriyash/Code-Regression huggingface dataset:
# Aizu Problem 0187: Stoning Fortune
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

def on_segment(p, q, r):
    # Given three colinear points p, q, r, the function checks if
    # point q lies on line segment 'pr'
    return q[0] <= max(p[0], r[0]) and q[0] >= min(p[0], r[0]) and \
           q[1] <= max(p[1], r[1]) and q[1] >= min(p[1], r[1])

def orientation(p, q, r):
    # To find orientation of ordered triplet (p, q, r).
    # The function returns following values
    #   0 --> p, q and r are colinear
    #   1 --> Clockwise
    #   2 --> Counterclockwise
    val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1])
    if val == 0:
        return 0
    return 1 if val > 0 else 2


def do_intersect(p1, q1, p2, q2):
    # The main function that returns true if line segment 'p1q1'
    # and 'p2q2' intersect.
    o1 = orientation(p1, q1, p2)
    o2 = orientation(p1, q1, q2)
    o3 = orientation(p2, q2, p1)
    o4 = orientation(p2, q2, q1)
    #
    # General case:
    if o1 != o2 and o3 != o4:
        return True
    #
    # Special Cases:
    # 
    # p1, q1 and p2 are colinear and p2 lies on segment p1q1
    if o1 == 0 and on_segment(p1, p2, q1):
        return True
    # p1, q1 and p2 are colinear and q2 lies on segment p1q1
    if o2 == 0 and on_segment(p1, q2, q1):
        return True
    # p2, q2 and p1 are colinear and p1 lies on segment p2q2
    if o3 == 0 and on_segment(p2, p1, q2):
        return True
    #  p2, q2 and q1 are colinear and q1 lies on segment p2q2
    if o4 == 0 and on_segment(p2, q1, q2):
        return True
    # Doesn't fall in any of the above cases:
    return False


def ip(xy1,xy2):
    ax,ay,bx,by = xy1; cx,cy,dx,dy = xy2
    dn = ((by-ay)*(dx-cx)-(bx-ax)*(dy-cy))*1.0
    x = ((cy*dx-cx*dy)*(bx-ax)-(ay*bx-ax*by)*(dx-cx))/dn
    y = ((cy*dx-cx*dy)*(by-ay)-(ay*bx-ax*by)*(dy-cy))/dn
    return x,y
 
def stoning_fortune(coord1, coord2, coord3):
    p1, q1 = coord1[:2], coord1[2:]
    p2, q2 = coord2[:2], coord2[2:]
    p3, q3 = coord3[:2], coord3[2:]
    if not do_intersect(p1, q1, p2, q2) or not do_intersect(p1, q1, p3, q3) or \
       not do_intersect(p3, q3, p2, q2) :
        return "kyo"
    x1, y1 = ip(coord1, coord2)
    x2, y2 = ip(coord2, coord3)
    x3, y3 = ip(coord3, coord1)
    area = abs(.5 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)))
    if area >= 1900000:
        return "dai-kichi"
    elif area >= 1000000:
        return "chu-kichi"
    elif area >= 100000:
        return "kichi"
    elif area > 0:
        return "syo-kichi"
    else:
        return "kyo"
    
    
while True:
    coord1 = [int(_) for _ in input().split()]
    if coord1 == [0, 0, 0, 0]:
        break
    coord2 = [int(_) for _ in input().split()]
    coord3 = [int(_) for _ in input().split()]
    print(stoning_fortune(coord1, coord2, coord3))

Measured memory_bytes: 7984
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,k,l,a,b,c,d,m;
    cin>>n;
    c=0;
    m=n;
    while(m>0)
    {
        a=m%10;
        c+=a;
        m=m/10;

    }
    if(n%c==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
    cout<<"No"<<endl;

    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

    int n = sc.nextInt();
    int tru = 0;
    int hnk = 0;

    for(int i = 0; i < n; i++){
      String t = sc.next();
      String h = sc.next();

      if(t.compareTo(h) < 0){
        hnk += 3;
      } else if(t.compareTo(h) > 0){
        tru += 3;
      } else if(t.equals(h)){
        tru += 1;
        hnk += 1;
      }
    }

    System.out.println(tru + " " + hnk);
  }
}



Measured memory_bytes: 30096
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer(x) cout<<endl<<"answer : "<<x<<endl<<endl;
#define op(x) cout<<x<<endl;
#define maxn 500005
#define lld_max 5000000000000000000
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0,l=0,r=0,mid=0,lo=0,hi=0;string s;bool flag=false;
        lld a,b,c,d;
        cin>>a>>b>>c>>d;
        x = a*c;
        y = b*d;
        z = a*d;
        p = b*c;
        ans = max(x,max(y,max(z,p)));
        op(ans);
    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


Measured memory_bytes: 3652
a, b, m= map(int, input().split())
a_l= list(map(int, input().split()))
b_l= list(map(int, input().split()))
xyc= [list(map(int, input().split())) for _ in range(m)]

ans=min(a_l)+min(b_l)

for i in range(m):
    ans=min(ans, a_l[xyc[i][0]-1]+b_l[xyc[i][1]-1]-xyc[i][2])

print(ans)

Measured memory_bytes: 38560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
 
  int th;
  int hn;
  int tn;
  int one;

  cin >> N;

  th = N/1000; // 1000の位
  hn = (N - th * 1000) / 100; // 100の位
  //tn = (N - (th * 1000 + hn * 100)) / 10;　//10の位
  tn = (N - (th * 1000 + hn * 100))/10;
  one = N - (th * 1000 + hn * 100 + tn * 10); //1の位
    
  if (th == hn) {
    if (hn == tn) {
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  else if (hn == tn){
  	if(tn == one){
    cout << "Yes" << endl;
    }
    else{
    cout << "No" << endl;
    }
  }
  else{
  cout << "No" << endl;
  }

}


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

using namespace std;
const long long mod=1e9+7;

int main(){
   int n;
   string s;
   cin>>n>>s;
   vector<long long> a(26);
   for(int i=0;i<n;i++){
       a[s[i]-'a']++;
   }
   long long ans=1;
   for(int i=0;i<26;i++){
       ans*=a[i]+1;
       ans%=mod;
   }
   
   cout<<ans-1<<endl;
}

   


Measured memory_bytes: 512
S = gets.chomp.chars

s = S.size
ans = (1..(S.size)).bsearch do |i|
  l = S[(s - i)..(i - 1)]

  !(l.all? { |c| c == '0' } || l.all? { |c| c == '1' })
end

if ans.nil?
  puts s
else
  puts ans - 1
end


Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    vector<ll>a(n+1,0);
    for(ll i=0;i<n;i++){
        cin >> a[i];
    }
    ll money=1000;
    ll kab=0;
    for(ll i=0;i<n;i++){
        if(a[i]>=a[i+1]){
            money+=kab*a[i];
            kab=0;
            continue;
        }
        ll x=money/a[i];
        kab+=x;
        money-=x*a[i];
    }
    cout << money << endl;
}

Measured memory_bytes: 3608
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
k = int(input())
x = [0] + list(map(int, input().split()))

ans = 0
for i in range(1, n+1):
    ans += min(abs(x[i] - 0) * 2, abs(x[i] - k) * 2)
print(ans)


Measured memory_bytes: 61864
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;
struct WeightedUnionFind {
	vl par; // 親の番号
	vl ws;  // 親との重みの差

	WeightedUnionFind(ll n) : par(n), ws(n) {
		for (int i = 0; i < n; i++) { par[i] = -1; }
	}

	ll find(ll x) {
		if (par[x] < 0) {
			return x;
		} else {
			ll parent = find(par[x]);
			ws[x] += ws[par[x]];
			return par[x] = parent;
		}
	}

	ll weight(int x) {
		find(x);
		return ws[x];
	}

	bool unite(int x, int y, int w) { // x <-(w)- y (x + w = y)
		w += weight(x);
		w -= weight(y);
		x = find(x); y = find(y);

		if (x != y) {
			if (par[y] < par[x]) {  // 多い方が根になるようにスワップする.
				int tmp = x; x = y; y = tmp; w = -w;
			}
			par[x] += par[y]; par[y] = x;
			ws[y] = w;
			return true;
		} else {
			return false;
		}
	}

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

	pair<bool, ll> diff(int x, int y) { // x - y を求める. 比較不能ならnull.
		if (!same(x, y)) { return pair<bool, ll>(false, -1); }
		return pair<bool,ll>(true, weight(x) - weight(y));
	}
};

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n, m; cin >> n >> m;
	WeightedUnionFind uf(n);
	REP(i, m) {
		ll l, r, d; cin >> l >> r >> d;
		l--, r--;
		if (uf.same(l, r)) {
			if (uf.diff(r, l).second != d) {
				cout << "No" << endl;
				return 0;
			}
		}
		uf.unite(l, r, d);
	}
	cout << "Yes" << endl;

	return 0;
}


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

int main() {

    int n, k; cin >> n >> k;
    int cnt = 0;
    int tmp = 1;
    while (n--) {
        if (tmp  * 2 < tmp + k) {
            tmp *= 2;
        }
        else {
            tmp += k;
        }
    }
    cout << tmp << endl;
    return 0;
}

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

typedef struct
{
  double x;
  double y;
}coordinate;

void Koch_curve( int, coordinate, coordinate);
  
coordinate C1,C2;

int main()
{
  int n;
  int i,j;

  C1.x=0,C1.y=0;   // 始点 p1
  C2.x=100,C2.y=0; // 終点 p2
  
  scanf("%d",&n);
  printf("%f %f\n", C1.x, C1.y);
  Koch_curve(n,C1,C2);
  
  return 0;
}

void Koch_curve( int n, coordinate C1, coordinate C2)
{
  coordinate s,t,u;
  if(n==0)
    {
      printf("%f %f\n", C2.x, C2.y);
      return;
    }
  
  s.x = (2*C1.x+1*C2.x)/3;
  s.y= (2*C1.y+1*C2.y)/3;
  
  t.x=(1*C1.x+2*C2.x)/3;
  t.y=(1*C1.y+2*C2.y)/3;

  double rad=M_PI *60/180;
  u.x=(t.x-s.x)*cos(rad)-(t.y-s.y)*sin(rad)+s.x;
  u.y=(t.x-s.x)*sin(rad)+(t.y-s.y)*cos(rad)+s.y;
  
  Koch_curve(n-1,C1,s);
  Koch_curve(n-1,s,u);
  Koch_curve(n-1,u,t); 
  Koch_curve(n-1,t,C2);
  
}



Measured memory_bytes: 2112
icase=0
if icase==0:
    s=input()
    s1=int(s[0:2])
    s2=int(s[2:4])
    if s1==0 or s1>=13:
        if 1<=s2 and s2<=12:
            print("YYMM")
        else:
            print("NA")
    else:
        if 1<=s2 and s2<=12:
            print("AMBIGUOUS")
        else:
            print("MMYY")

Measured memory_bytes: 3060
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#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>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

int main() {

    int N;
    cin >> N;

    vector<int> p(N);
    for (int i = 0; i < N; i++) cin >> p[i], p[i]--;

    int ans = 0;
    for (int i = 0; i < N - 1; i++) if (p[i] == i) swap(p[i], p[i + 1]), ans++;
    if(p[N-1] == N-1) ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
using namespace std;
#define U(v) cerr << #v << ": " << (v) << endl

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

constexpr long long M = 998244353;

int N, A, B;
long long K;

typedef long long ll;

long long mod = M;
ll f[300010] = {0}; // f(n) = (n!) % mod

// 繰り返し二乗法 O(log n)
ll mod_pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x*x % mod;
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return mod_pow(x, mod-2) % mod;
}

// nCr % mod
ll comb(int n, int r){
    return (((f[n] * mod_inv(f[r])) % mod) * mod_inv(f[n-r])) % mod;
}

class {
unsigned y = 2463534242;
public:
unsigned next() {
    return y ^= (y ^= (y ^= y << 13) >> 17) << 5;
}
int next(int b) {
    return next() % b;
}
int next(int a, int b) {
    return next(b - a) + a;
}
double nextDouble(double b = 1) {
    return b * next() / 4294967296.0;
}
double nextDouble(double a, double b) {
    return nextDouble(b - a) + a;
}
int operator() (int b) {
    return next(b);
}
} rando;

int main() {
    f[0] = f[1] = 1;
    for(int i=2; i<=300005; ++i) f[i] = (i * f[i-1]) % mod;
    while (cin >> N >> A >> B >> K) {
        long long re = 0;
        for (int i = 0; i <= N; ++i) {
            if ((K - (long long)i * A) % B == 0 && (K - (long long)i * A) / B >= 0 && (K - (long long)i * A) / B <= N) {
                int j = (int)((K - (long long)i * A) / B);
                re += comb(N, i) * comb(N, j) % M;
                re %= M;
            }
        }
        cout << re << endl;
    }
    return 0;
}


Measured memory_bytes: 3192
n=input()
l=[]
m=[]
for i in range(len(n)-2):
    x=str(n[i])+str(n[i+1])+str(n[i+2])
    l.append(x)
for k in range(len(l)):
    d=int(l[k])-753
    if d>=0:
        m.append(d)
    else:
        d=d*-1
        m.append(d)
print(min(m))

Measured memory_bytes: 3060
if __name__ == '__main__':
	N = int(input())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))

	ans = 0
	for i in range(N):
		if (A[i]+A[i+1]) > B[i]:
			ans = ans + B[i]
			if A[i] > B[i]:
				pass
			else:
				A[i+1] = A[i+1] + A[i] - B[i]
		elif (A[i]+A[i+1]) <= B[i]:
			ans = ans + A[i] + A[i+1]
			A[i+1] = 0
	print(ans)

Measured memory_bytes: 19004
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;
    vector<int> hen[50];
    int oya[50];
    void bfs(int a){
        for(int i=0;i<hen[a].size();i++){
            if(oya[hen[a][i]]==-2){
                oya[hen[a][i]]=a;
                bfs(hen[a][i]);

            }
        }
    }
    int modpow(int a, int n) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a ;
        a = a * a;
        n >>= 1;
    }
    return res;
}
        signed main() {
           
        int n;
        cin>>n;
        
        int a,b;
        for(int i=0;i<n-1;i++){
            cin>>a>>b;a--;b--;
            hen[a].push_back(b);
            hen[b].push_back(a);

        }
        for(int i=0;i<n;i++)oya[i]=-2;
    oya[0]=-1;
    bfs(0);
   // cerr<<'k';
    int m;
    cin>>m;
    bool x[m][n];
            int u,v;
            for(int i=0;i<m;i++){
                for(int j=0;j<n;j++)x[i][j]=false;
                cin>>u>>v;u--;v--;
                while(u){
                    x[i][u]=!x[i][u];
                    u=oya[u];
                }
                  while(v){
                    x[i][v]=!x[i][v];
                    v=oya[v];
                }
            }
            bool o;int p,q;int ans=0;
            for(int i=0;i<(1<<m);i++){
                p=0;q=1;
                 for(int k=0;k<m;k++){
                        if(i&(1<<k)){
                           q*=-1;
                            
                        }
                    }
                for(int j=1;j<n;j++){
                    o=false;
                    for(int k=0;k<m;k++){
                        if(i&(1<<k)){
                            o|=x[k][j];
                            
                        }
                    }
                    if(o)p++;
                }
                ans+=q*(1ll<<(n-1-p));
            }
    cout<<ans;
         return 0;

        }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
    if (b==0) return 1;
    ll c = power(a,b>>1);
    c = (c*c)%mod;
    if (b&1) return (c*a)%mod;
    return c;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)3e5+5;
const int Q = 301;

void solve() {
	int a,b;
  cin>>a>>b;
  int c = min(a,b);
  int n = a+b-c;
  REP(i,0,n-1) cout<<c;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc_165b
{
    class Program
    {
        static void Main(string[] args)
        {
            long fin = long.Parse(Console.ReadLine());

            int year = 0;
            long money = 100;

            while(money < fin)
            {
                money = money + money/100;
                year = year + 1;
            }

            Console.WriteLine(year);

            Console.Read();
            
        }
    }
}


Measured memory_bytes: 27348
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double A = sc.nextInt();
		double B = sc.nextInt();
		double K = (A + B) / 2;

		if (K == (int) K) System.out.println((int) K);
		else System.out.println("IMPOSSIBLE");
	}
}

Measured memory_bytes: 23764
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
s0=['#']*(w+2)
s.insert(0,s0)
s.append(s0)
for i in range(1,h+1):
	s[i].append('#')
	s[i].insert(0,'#')
	
for ai in s:
  print("".join(ai))

Measured memory_bytes: 3064
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let n = read int
    let ss = (read string).ToCharArray()

    let dp = Array2D.create (n + 1) (n + 1) 0

    for i = n - 1 downto 0 do
        for j = n - 1 downto 0 do
            if ss.[i] = ss.[j] then
                dp.[i,j] <- dp.[i+1,j+1] + 1

    let mutable ans = 0
    for i = 0 to n - 1 do
        for j = 0 to n - 1 do
            if i < j then
                ans <- max ans (min dp.[i,j] (j - i))

    printfn "%i" ans
    0

Measured memory_bytes: 110556
#include<algorithm>
#include<iostream>
#include<cstdio>

const int INF = 1001;

int n, m;
int dist[20][20];
int s, e, x, y;

int main()
{
	for( int i = 0; i != 20; ++i )
		for( int j = 0; j != 20; ++j )
				dist[i][j] = i == j ? 0 : INF;

	std::cin >> n >> m;
	
	for( int i = 0; i != m; ++i )
	{
		int a, b, c, d;
		scanf( "%d,%d,%d,%d", &a, &b, &c, &d );
		dist[a-1][b-1] = c;
		dist[b-1][a-1] = d;
	}

	scanf( "%d,%d,%d,%d", &s, &e, &x, &y );

	for( int k = 0; k != n; ++k )
		for( int i = 0; i != n; ++i )
			for( int j = 0; j != n; ++j )
				dist[i][j] = std::min( dist[i][j], dist[i][k] + dist[k][j] );

	std::cout << x - y - dist[s-1][e-1] - dist[e-1][s-1] << std::endl;

	return 0;
}

Measured memory_bytes: 1240
import sys
import copy

def main():

	input = sys.stdin.readline

	N, K = list(map(int,input().strip().split()))
	S = list(input().strip())

	LRcount = 0
	RLcount = 0
	count = 0
	for i in range(N-1):
		if S[i]==S[i+1]:
			count = count+1
		if S[i]=='L' and S[i+1]=='R':
			LRcount = LRcount+1
		elif S[i]=='R' and S[i+1]=='L':
			RLcount = RLcount+1

	cmin = min(LRcount,RLcount)
	if LRcount!=RLcount:
		ne = 1
	else:
		ne = 0

		
	if K<=cmin:
		count = count+K*2
	else:
		count = count+cmin*2
		if K>cmin:
			count = count+ne

	print(count)

if __name__ == "__main__":
    main()


Measured memory_bytes: 49600
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        String str1 = lines[0];
        int n = Integer.parseInt(str1);
        int tower1[][] = new int[3][10];
        int tower2[][] = new int[3][10];
        int tower3[][] = new int[3][10];
        int tower4[][] = new int[3][10];
        for(int i = 1; i <= n; ++i){
            String[] tinfo = lines[i].split(" ");
            int b = Integer.parseInt(tinfo[0]);
            int f = Integer.parseInt(tinfo[1]);
            int r = Integer.parseInt(tinfo[2]);
            int v = Integer.parseInt(tinfo[3]);
            if(b == 1){
                tower1[f - 1][r - 1] += v;
            } else if(b == 2){
                tower2[f - 1][r - 1] += v;
            } else if(b == 3){
                tower3[f - 1][r - 1] += v;
            } else if(b == 4){
                tower4[f - 1][r - 1] += v;
            }
        }
        for(int i = 0; i < 3; ++i){
            for(int j = 0; j < 10; ++j){
                System.out.print(" ");
                System.out.print(tower1[i][j]);
            }
            System.out.println();
        }
        System.out.println("####################");
        for(int i = 0; i < 3; ++i){
            for(int j = 0; j < 10; ++j){
                System.out.print(" ");
                System.out.print(tower2[i][j]);
            }
            System.out.println();
        }
        System.out.println("####################");
        for(int i = 0; i < 3; ++i){
            for(int j = 0; j < 10; ++j){
                System.out.print(" ");
                System.out.print(tower3[i][j]);
            }
            System.out.println();
        }
        System.out.println("####################");
        for(int i = 0; i < 3; ++i){
            for(int j = 0; j < 10; ++j){
                System.out.print(" ");
                System.out.print(tower4[i][j]);
            }
            System.out.println();
        }
    }
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
}


Measured memory_bytes: 26876
#pragma GCC target (*sse4.2*)
#pragma GCC optimization ("O3")
#pragma GCC optimize ("Ofast")
#define mod 1000000007
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define PB push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define vvii vector<vii>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define read(x) long long x;cin>>x;
#define FOR(a,b,c,d) for(int a=b;a<=c;a+=d)
#define MP make_pair
#define F first
#define S second
#define debug(x) cout<<("#x)<<": "<<(x)<<"\n"
#define SZ(x) x.size()
#define INF (1<<31)-1

using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
typedef long long ll;
typedef unsigned long long ull;
typedef long double d64;


int main(){
fast
read(n);
vector<string>x(n);
for(int i=0;i<n;i++){
    cin>>x[i];
}
ll tle=0 ,ac=0,re=0,wa=0;
for(int i=0;i<x.size();i++){
    if(x[i]=="TLE")tle++;
    if(x[i]=="AC")ac++;
    if(x[i]=="WA")wa++;
    if(x[i]=="RE")re++;
}
cout<<"AC x "<<ac<<"\n";
cout<<"WA x "<<wa<<"\n";
cout<<"TLE x "<<tle<<"\n";
cout<<"RE x "<<re<<"\n";


return 0;
}


Measured memory_bytes: 6364
def isStable(before_sort, after_sort):
    num = len(before_sort)
    
    for i in range(0, num-1):
        for j in range(i+1, num):
            for a in range(0, num-1):
                for b in range(a+1, num):
                    if before_sort[i][1] == after_sort[j][1] and \
                       before_sort[i] == after_sort[b] and \
                       before_sort[j] == after_sort[a]:
                        return False
    return True

def isStable2(sorted_data, bubble_sort_data):
    for i in range(0, len(sorted_data)):
        if sorted_data[i] != bubble_sort_data[i]:
            return False
    return True
    
def BubbleSort(c, n):
    for i in range(0, n):
        for j in range(n-1, i, -1):
            if int(c[j][1]) < int(c[j-1][1]):
                c[j], c[j-1] = c[j-1], c[j]

def SelectionSort(c, n):
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(c[j][1]) < int(c[minj][1]):
                minj = j
        c[i], c[minj] = c[minj], c[i]
    
num = int(input())
data = input().split(' ')

copy_data = data.copy()
BubbleSort(copy_data, num)
print(' '.join(copy_data))
if isStable(copy_data, copy_data):
    print("Stable")
else:
    print("Not stable")

bubble_sort_data = data.copy()
SelectionSort(bubble_sort_data, num)
print(' '.join(bubble_sort_data))
if isStable(bubble_sort_data, copy_data):
    print("Stable")
else:
    print("Not stable")

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  
  int ans = 0;
  for ( int i = 0; i < n/2; i++ ) {
    if ( s[i] != s[n-i-1] ) {
      ans++;
    }
  }

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


Measured memory_bytes: 3624
#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;


int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }
    if (a >= b) {
        gcd(b, a%b);
    }
    else {
        gcd(a, b%a);
    }

}

int main()
{
    int N, d = 1;
    int sum = 0;
    cin >> N;
    int* A = (int*)malloc(sizeof(int)*(N + 1));
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        for (int k = 2; k <=floor(sqrt(A[i])); k++) {
            d=gcd(k, A[i]);
            if (d != 1) {
                break;
            }
        }
        if (d == 1) {
            sum++;
        }
        
    }
    cout << sum << "\n";
    free(A);
    return 0;
}

Measured memory_bytes: 3092
def count_coin_maximum():
    a_button, b_button = map(int, input().split())
    if a_button == b_button:
        return a_button + a_button
    elif a_button > b_button:
        return a_button + max(a_button - 1, b_button)
    else:
        return b_button + max(b_button - 1, a_button)


print(count_coin_maximum())


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

using namespace std;

typedef long long ll;
typedef pair< ll, ll > pll;

const double pi = 3.14159265358979323846;

#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define vl vector< ll >

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

  ll N;
  cin >> N;

  for (int i = N; i < 1000; i++) {
    string s = to_string(i);

    if (s[0] == s[1] && s[1] == s[2]) {
      cout << i << "\n";
      return 0;
    }
  }

  cout << N * 2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>
#include <algorithm>
#include<iomanip>
#include<map>
#define INF 1000000000
#define LM 55555
#define LL long long
using namespace::std;


long long now, A[2][100],AA[2][100],num, N, K, M, ans,sosu[100000];
string S, T;
bool h,w[10], k[100],con[300];
char cc;

int main() {

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[0][i];
		if(i>0)AA[0][i] = AA[0][i - 1] + A[0][i];
		else AA[0][i] = A[0][i];
	}

	for (int i = 0; i < N; i++) {
		cin >> A[1][i];
		if (i>0)AA[1][i] = AA[1][i - 1] + A[1][i];
		else AA[1][i] = A[1][i];
	}
	ans = A[0][0] + AA[1][N - 1];
	for (int i = 1; i < N; i++) {
		now = AA[0][i] + (AA[1][N - 1] - AA[1][i - 1]);
		ans = max(ans, now);
	}
	cout <<ans << endl;
	return 0;

}

Measured memory_bytes: 256
from operator import mul
from functools import reduce


def inpl():
    return list(map(int, input().split()))


def cmb(n, r):
    # combination
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


N, M = inpl()

print(cmb(N, 2) + cmb(M, 2))


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int, int>P;
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int *x) { int k, m = 0; *x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { *x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; *x = (*x) * 10 + k - '0'; }if (m)(*x) = -(*x); }
void reader(int *x, int *y) { reader(x); reader(y); }
void reader(int *x, int *y, int *z) { reader(x); reader(y); reader(z); }
void writer(int x, char c) { int i, sz = 0, m = 0; char buf[10]; if (x<0)m = 1, x = -x; while (x)buf[sz++] = x % 10, x /= 10; if (!sz)buf[sz++] = 0; if (m)mypc('-'); while (sz--)mypc(buf[sz] + '0'); mypc(c); }

int n, m;
int bit[100001];
P v[300000];

void add(int k, int x) {
	while (k <= m) {
		bit[k] += x;
		k += k &-k;
	}
}
int sum(int k) {
	int res = 0;
	while (k > 0) {
		res += bit[k];
		k -= k&-k;
	}
	return res;
}
int main() {
	reader(&n, &m);
	rep(i, n) {
		int l, r; reader(&l, &r);
		v[i] = P(r - l + 1, l);
	}
	sort(v, v + n);
	int s = 0;
	for (int i = 1; i <= m; i++) {
		while (s < n && v[s].first < i) {
			add(v[s].second, 1); add(v[s].second + v[s].first, -1);
			s++;
		}
		int ans = n - s;
		for (int j = 0; j <= m; j += i)ans += sum(j);
		writer(ans, '\n');
	}
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <map>
#include <bitset>
#include <queue>
using namespace std;

int main()
{
    int n[4];
    cin >> n[0] >> n[1] >> n[2] >> n[3];
    bool check[4] = {false, false, false, false};
    int num[4] = {1, 9, 7, 4};
    for (int i=0; i<4; ++i){
        for (int j=0; j<4; ++j){
            if(n[i] == num[j]){
                check[j] = true;
            }
        }
    }
    string ans = "YES";
    for (int i=0; i<4; ++i){
        if(check[i] == false){
            ans = "NO";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
bool in(int x,int y){
  if(x<0||x>9||y<0||y>9) return false;
  return true;
}
int main(){
  int pa[10][10]={{}};
  string str;
  int i,j;
  while(cin >> str){
    int x=str[0]-'0',y=str[2]-'0',s=str[4]-'0';
    if(s==1){
      for(i=-1;i<=1;i++){
	for(j=-1+abs(i);j<=1-abs(i);j++){
	  if(in(x+i,y+j)) pa[x+i][y+j]++;
	}
      }
    }else if(s==2){
      for(i=-1;i<=1;i++){
	for(j=-1;j<=1;j++){
	  if(in(x+i,y+j)) pa[x+i][y+j]++;
	}
      }
    }else if(s==3){
      for(i=-2;i<=2;i++){
	for(j=-2+abs(i);j<=2-abs(i);j++){
	  if(in(x+i,y+j)) pa[x+i][y+j]++;
	}
      }
    }
  }
  int o=0,m=0;
  for(i=0;i<10;i++){
    for(j=0;j<10;j++){
      //cout << pa[i][j];
      m=max(m,pa[i][j]);
      if(pa[i][j]==0) o++;
    }
    //cout << endl;
  }
  cout << o << endl << m << endl;
  return 0;
}

Measured memory_bytes: 1180
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static string[] Solve(int H, int W, int A, int B)
        {
            var lines = new string[H];
            for (int i = 0; i < B; ++i)
            {
                lines[i] = new string('0', A) + new string('1', W - A);
            }
            for (int i = B; i < H; ++i)
            {
                lines[i] = new string('1', A) + new string('0', W - A);
            }
            return lines;
        }

        static void Main(string[] args)
        {
            var V = ReadInts();
            var lines = Solve(V[0], V[1], V[2], V[3]);
            foreach (string line in lines)
            {
                Console.WriteLine(line);
            }
        }
    }
}


Measured memory_bytes: 18496
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(12); }; }aaaa;

int main() {
    int N;
    cin >> N;
    write(N * N * N);
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

static class NagataKanaIsAGenius {
    public static void Main() {
        int n=int.Parse(Console.ReadLine());
        int[]c=new int[n-1];
        int[]s=new int[n-1];
        int[]f=new int[n-1];
        for(int i=0;i<n-1;i++){
            int[]csf=Console.ReadLine().Split().Select(int.Parse).ToArray();
            c[i]=csf[0];
            s[i]=csf[1];
            f[i]=csf[2];
        }
        for(int j=0;j<n;j++){
            int ans=0;
            for(int i=j;i<n-1;i++){
                ans=Math.Max(ans,s[i]);
                if(ans%f[i]!=0){
                    ans+=f[i]-ans%f[i];
                }
                ans+=c[i];
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

fn main() {
    input!{
        abcd_v: chars,
    }

    let abcd = abcd_v.iter().map(|c| c.to_digit(10).unwrap() as i64).collect::<Vec<_>>();


    let ops_iter = (0..(1 << 3)).map(|n| {
        let mut ops = Vec::new();
        for i in 0..3 {
            if n & (1 << i) == 0 {
                ops.push('+');
            } else {
                ops.push('-');
            }
        }

        ops
    });

    let mut correct_ops = None;
    for ops in ops_iter {
        let mut acc = abcd[0];
        for (i, &op) in ops.iter().enumerate() {
            if op == '+' {
                acc += abcd[i+1];
            } else {
                acc -= abcd[i+1];
            }
        }

        if acc == 7 {
            correct_ops = Some(ops);
        }
    }

    print!("{}", abcd_v[0]);
    for (num, op) in abcd_v.iter().skip(1).zip(correct_ops.unwrap().iter()) {
        print!("{}{}", op, num);
    }
    println!("=7");
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define REP(i, n) for(int i = 0;i < n;i++)
#define RE(i, n) for(int i=1;i<=n;i++)
int main(){
        long N,M,R;
        long d[201][201]={0};
        cin>>N>>M>>R;
        vector<long> r(R);
        REP(i,R)
                cin>>r[i];
        sort(begin(r),end(r));
        RE(i,N){
                RE(j,N){
                        if(i!=j)
                                d[i][j]=INF;
                }
        }
        REP(i,M){
                long a,b,c;
                cin>>a>>b>>c;
                if(d[a][b]==INF)
                        d[a][b]=d[b][a]=c;
        }
        RE(k,N){
                RE(j,N){
                        RE(i,N)
                                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
                }
        }
        unsigned long min=-1;
        do{
                long sum=0;
                REP(i,R-1)
                        sum+=d[r[i]][r[i+1]];
                if(sum<min)
                        min=sum;
        }while(next_permutation(begin(r),end(r)));
        cout<<min;
}

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

template<typename T>
class UnionFind {
    std::map<T, T> parent;
    std::map<T, int> rank;
public:
    void unionSet(const T& a, const T& b) {
        T x = findSet(a), y = findSet(b);
        if(rank[x] < rank[y]) std::swap(x, y);
        parent[y] = x;
        if(rank[x] == rank[y]) rank[x] += 1;
    }
    const T findSet(const T& x) {
        if(!parent.count(x)) {
            rank[x] = 1;
            return parent[x] = x;
        }
        return (parent[x] == x) ? x : (parent[x] = findSet(parent[x]));
    }
};

int main() {
    int n, q;
    cin >> n;
    UnionFind<int> set;
    for(cin >> q; q > 0; --q) {
        int com, x, y;
        cin >> com >> x >> y;
        if(com) {
            cout << (set.findSet(x) == set.findSet(y)) << endl;
        } else {
            set.unionSet(x, y);
        }
    }
}

Measured memory_bytes: 2136
from collections import deque

N,M = map(int,input().split())
A = [[] for i in range(N)]
checkd = [False]*N
for _ in range(M):
    a,b = (map(lambda a: int(a)-1, input().split()))
    A[a].append(b)
    A[b].append(a)
nextS = set(range(N))
ans = 0
while len(nextS)>0:
    s = nextS.pop()
    if checkd[s]: 
        continue
    count = 0
    que = deque([s])
    while len(que)>0:
        nn = que.popleft()
        if checkd[nn]:
            continue
        checkd[nn] = True
        nextS.discard(nn)
        count += 1
        que.extend(A[nn])
    ans = max(count,ans)


print(ans)




Measured memory_bytes: 62292
#include <stdio.h>

int h, w;
char mp[25][25];
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};

int dfs(int sy, int sx);

int main()
{
    scanf("%d %d", &w, &h);
    while (h != 0 && w != 0) {

        int sy, sx;

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                scanf(" %c ", &mp[i][j]);

                if (mp[i][j] == '@') {
                    sy = i;
                    sx = j;
                }
            }
        }

        printf("%d\n", dfs(sy, sx));
        
        scanf("%d %d", &w, &h);
    }

    return 0;
}

int dfs(int y, int x)
{
    if (y < 0 || y >= h ||
        x < 0 || x >= w ||
        mp[y][x] == '#') {
        return 0;
    }

    int rec = 1;
    mp[y][x] = '#';

    for (int i = 0; i < 4; i++) {
        int ny = y + dy[i];
        int nx = x + dx[i];

        rec += dfs(ny, nx);
    }

    return rec;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define rep(i,n,z) for(int i=z;i<n;i++)
#define rrep(i,z) for(int i=z;i>=0;i--)
#define nl cout<<endl
#define vi vector<int>
#define vlli vector<long long int>
#define umap unordered_map
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define ipair pair <int,int>
#define llipair pair <lli,lli>
#define pq priority_queue
#define displaymatrix(a,m,n) for(int i=0;i<m;i++){for(int j=0;j<n;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define printarray(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}nl;
#define vinput(a,n) vlli a(n);rep(i,n,0)cin>>a[i]
#define ainput(a,n) rep(i,n,0)cin>>a[i]
#define SO(a) sort(a.begin(),a.end())
#define all(x) (x).begin(),(x).end()
#define SOP(a,comp) sort(a.begin(),a.end(),comp)
#define inf INT_MAX
#define endl '\n'
 
int main()
{
    fastio;
    int ans = 0;
    lli n,m,k,left;
    cin>>n>>m>>k;
    vinput(a,n);
    vinput(b,m);

    rep(i,n,1){
        a[i] += a[i - 1];
    }

    rep(i,m,1){
        b[i] += b[i - 1];
    }

    rep(i,n,0){
        if(a[i] > k)break;
        left = k - a[i];

        ans = max(ans,i + 1 + (int)(upper_bound(all(b),left) - b.begin()));
    }

    rep(i,m,0){
        if(b[i] > k)break;
        left = k - b[i];

        ans = max(ans,i + 1 + (int)(upper_bound(all(a),left) - a.begin()));
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 6344
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val s = next().toCharArray()
    println(s.count { it == '1' })
}

Measured memory_bytes: 33512
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n,l;
    scanf("%d%d",&n,&l);
    int sum = 0;
    int sub = 10000;
    for(int i = 0;i < n;i++){
        sum += l + i;
        if(abs(sub) > abs(l + i)){
            sub = l + i;
        }
    }

    sum -= sub;
    printf("%d",sum);
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>
#include <map>
#include <string>
#include <climits>
#include <set>
#include <sstream>
#include <utility>
#include <ctime>
#include <cassert>
#include <fstream>
using namespace std;
typedef long long LL;
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MAX(a,b) ((a >= b) ? (a) : (b))
#define MIN(a,b) ((a >= b) ? (b) : (a))
#define ABS(a) (((a) > 0) ? (a) : (-a))
#define MP make_pair
#define PB push_back
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))

int main() {

	char s[200001];
	int l ,i;
	scanf("%s", s);
	l = strlen(s);

	if(s[0] == '?') {

		if(l<2) {
			s[0] = 'D';
		} else {

			if(s[1] == 'D' || s[1] == '?') {
				s[0] = 'P';
			} else if(s[1] == 'P') {
				s[0] = 'D';
			}
		}
	}

	for(i = 1 ; i < l ;i++) {

		if(s[i] == '?') {

			if(s[i-1] == 'P') {
				s[i] = 'D';
			} else if(s[i-1] == 'D') {

				if(s[i+1] == '?' || s[i+1] == 'D') {
					s[i] = 'P';
				} else {
					s[i] = 'D';
				}
			}
		}
	}

	// for(i = l-2; i>=0 ;i--) {

	// 	if(s[i] == '?') {

	// 		if(s[i+1] == 'P') {
	// 			s[i] = 'D';
	// 		} else if (s[i+1] == 'D') {
	// 			s[i] = 'P';
	// 		}
	// 	}
	// }

	printf("%s\n", s);
	return 0;
}

Measured memory_bytes: 3996
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: i64,
  }
  if n % 2 == 1 {
    puts!("0\n");
    return;
  }
  let mut five = 0i64;
  let mut pow = 5i64;
  while pow <= n {
    let count = n / pow;
    five += count / 2;
    pow *= 5;
  }
  puts!("{}\n", five);
}


Measured memory_bytes: 4352