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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N, H, W; cin >> N >> H >> W;
  int ans=0;
  loop(N){
    int a, b; cin >> a >> b;
    if(H<=a and W<=b)ans++;
  }
  cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
 int A,B,C,K;
  cin >>A>>B>>C>>K;
  if (K<A)cout << K<<endl;
  if(K>=A && K<= A+B)cout <<A<<endl;
  if(K>A+B)cout <<A-(K-A-B)<<endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main(){
    int H,R;
    cin>>H>>R;
    if(H<0 && H*-1==R){
        cout<<"0"<<'\n';
    }if(H<0 && H*-1>R){
        cout<<"-1"<<'\n';
    }if(H>=0 || H*-1<R){
        cout<<"1"<<'\n';
    }
    return(0);
}


Measured memory_bytes: 3080
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
const int INF = 1e+9;

int main() {
	int n;
	cin >> n;
	vector<int> h(n), dp(n + 10, INF);
	for (int i = 0; i < n; ++i) cin >> h[i];
	dp[0] = 0;
	for (int i = 0; i < n - 1; ++i) {
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		if (i < n - 2)
			dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  s.pop_back();
  s.pop_back();
  while(s.size() > 1){
    string a,b;
    a = s.substr(0,s.size()/2);
    b = s.substr(s.size()/2,s.size()/2);
    if(a == b){
      cout << s.size() << endl;
      return 0;
    }
    s.pop_back();
    s.pop_back();
  }
  cout << 1 << endl;
}


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

int main(){
    int H, W;
    cin >> H >> W;
    char grid[H][W];
    for (int i=0; i<H; ++i){
        for (int j=0; j<W; ++j){
            cin >> grid[i][j];
        }
    }
    int dx[] = {0, 0, -1, 1};
    int dy[] = {-1, 1, 0, 0};

    bool ok = true;
    for (int i=0; i<H; ++i){
        for (int j=0; j<W; ++j){
            if (grid[i][j] == '#'){
                ok = false;
                for (int k=0; k<4; ++k){
                    if (i+dy[k] < 0 || i+dy[k] >= H || j+dx[k] < 0 || j+dx[k] >= W) continue;
                    if (grid[i+dy[k]][j+dx[k]] == '#'){
                        ok = true;
                        break;
                    }
                }
            }
            if (!ok) break;
        }
        if (!ok) break;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import Control.Monad

main = do
  li <- getLine
  let [n,m] = map read $ words li
  abs <- forM [1..n] (\_ -> do
    li <- getLine
    let [a,b] = map read $ words li
    return (a,b)
    )
  cds <- forM [1..m] (\_ -> do
    li <- getLine
    let [c,d] = map read $ words li
    return (c,d)
    )
  let ans = compute abs cds
  mapM_ print ans

compute :: [(Int,Int)] -> [(Int,Int)] -> [Int]
compute abs cds = map (nearest cds) abs

nearest :: [(Int,Int)] -> (Int,Int) -> Int
nearest cds ab = snd $ minimum [ (mdis ab cd, j) | (cd,j) <- zip cds [1..] ]

mdis :: (Int,Int) -> (Int,Int) -> Int
mdis (a,b) (c,d) = abs (a-c) + abs (b-d)


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

int main() {
 int K;
  cin>>K;
  int A,B;
  cin>>A>>B;
  for(int i=A;i<=B;i++){
    if(i%K==0){
      cout<<"OK"<<endl;
      break;
    }
    else if (i==B){
      cout<<"NG"<<endl;
    }
  }
  
}

Measured memory_bytes: 3636
import fractions
A,B,C,D = map(int,input().split())
def numbers(N,C,D):
  G = fractions.gcd(C,D)
  lcm = (C*D)//G
  return N - N//C - N//D + N//lcm
print(int(numbers(B,C,D)-numbers(A-1,C,D)))


Measured memory_bytes: 5048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var f = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if ((Math.Abs(f[1] - f[0]) <= f[3] &&
                Math.Abs(f[2] - f[1]) <= f[3] )||
                Math.Abs(f[2] - f[0]) <= f[3])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13396
K, S = map(int, input().split())

cnt = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - (x + y)
        if 0 <= z <= K:
            cnt += 1

print(cnt)

# 全探索の3重ループだとTLE

# x,yを決めると x+y+z=S となるような z が一意に定まる
# そのようなzが 問題文の条件(0<=z<=K)であり得るか を考える

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(s) s.begin(),s.end()

int main(void){
    int n;
    while(cin>>n, n){
        vector<string> s(n);
        int a[256] = {};
        bool not_zero[256] = {};
        rep(i,n){
            cin>>s[i];
            int k = s[i].size();
            if(k>1) not_zero[s[i][0]] = true;
            reverse(all(s[i]));
            rep(j,k){
                a[s[i][j]] += pow(10,j)*(i==n-1 ? -1 : 1);
            }
        }
        
        set<char> st;
        rep(i,n){
            for(char c:s[i]){
                st.insert(c);
            }
        }
        string char_list;
        for(char c : st) char_list += c;
        char_list += string(10-(int)st.size(), '-');
        sort(all(char_list));
        int res = 0;
        do{
            if(not_zero[char_list[0]]) continue;
            int sum = 0;
            rep(i,10) sum += i*a[char_list[i]];
            if(sum == 0) res++;
        }while(next_permutation(all(char_list)));
        cout<<res<<endl;
    }

    return 0;
}



Measured memory_bytes: 3328
#abc141d
import heapq

n,m=map(int,raw_input().split())
a=map(int,raw_input().split())
l=[]
for i in xrange(n):
 l.append(-a[i])
q=[]
for i in l:
 heapq.heappush(q,i)
for i in range(m):
 temp=-heapq.heappop(q)
 heapq.heappush(q,-(temp/2))
res=-sum(q)
print res


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< int, int > P;   
typedef pair< int, P > PP;

//-----------------------------------------------------------------------------

int f(int x) {
    int res = 0;
    while(x) {
        res += x % 10;
        x/= 10;
    }
    return res;
}

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

    int n;
    cin >> n;
    int mi = INF;
    FOR(a, 1, n) {
        int b = n - a;
        int sum = f(a) + f(b);
        mi = min(mi, sum);
    }
    cout << mi << endl;

    return 0;
}


Measured memory_bytes: 896
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias Pair = Tuple!(long, "number", long, "times");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long x, y, count;
    scan(x, y);
    while(x <= y)
    {
        x *= 2;
        count++;
    }
    count.writeln();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f ( ll x ) {
    if ( x == 0 ) return 0;
    else return x % 10 + f ( x / 10 );
}
int main() {
    std::ios::sync_with_stdio ( false );
    int k;
    cin >> k;
    int num = 0;
    ll ans = 1;
    ll p = 1;
    while ( num < k ) {
        cout << ans << endl;
        ll ans1 = ans + p;
        ll ans2 = ans + p * 10;
        if ( ans1 * f ( ans2 ) <= ans2 * f ( ans1 ) ) {
            ans = ans1;
        } else {
            ans = ans2;
            p *= 10;
        }
        num++;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define ff(x) cerr << #x << " is " << x << '\n'
#define FL freopen("in", "r", stdin),freopen("out", "w", stdout);
#define time cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b) 
int main(){
    //FL;
    fin;
    int n, k;
    string s;
    cin >> n >> k >> s;
    k--;
    s[k] = tolower(s[k]);
    cout << s << '\n';
    time;
    return 0;
}   

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	
	int a,i,j,w,z;
	long goukei=0;
	scanf("%d",&a);
	int n[10000];
	for(i=0;i<a;i++){
		scanf("%d",&n[i]);
		goukei+=n[i];
	}
	for(i=0;i<a;i++){
		for(j=i;j<a;j++){
			if(n[i]<n[j]){
				w=n[i]; n[i]=n[j]; n[j]=w;
			}
		}
	}
	printf("%d ",n[a-1]);
	printf("%d ",n[0]);
	printf("%ld\n",goukei);
	
	return 0;
}


Measured memory_bytes: 2120
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////


int main() {
	ll N, K;
	cin >> N >> K;
	vll h(N + 1);
	repn(i, N) cin >> h[i];

	vll dp(N + 1, INF);
	dp[1] = 0;
	for(ll i=2; i<=N; i++) {
		repn(j, K) {
			if (i - j >= 1) { dp[i] = min(dp[i], dp[i-j] + abs(h[i-j] - h[i])); }
		}
	}

	cout << dp[N] << endl;
}



Measured memory_bytes: 4832
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    zero_list = []
    one_list = []
    for i in range(n):
        if i % 2 == 0:
            zero_list.append(num_list[i])
        else:
            one_list.append(num_list[i])

    zero_c = Counter(zero_list)
    one_c = Counter(one_list)

    zero_saihin_key = zero_c.most_common()[0][0]
    zero_saihin_val = zero_c.most_common()[0][1]
    one_saihin_key = one_c.most_common()[0][0]
    one_saihin_val = one_c.most_common()[0][1]

    if zero_saihin_key != one_saihin_key:
        print(n - zero_saihin_val - one_saihin_val)
        exit()

    if num_list.count(zero_saihin_key) == n:
        print(n//2)
        exit()

    if len(zero_c) == 1:
        print(n//2 - one_c.most_common()[1][1])
    elif len(one_c) == 1:
        print(n//2 - zero_c.most_common()[1][1])
    else:
        count1 = n - zero_saihin_val - one_c.most_common()[1][1]
        count2 = n - zero_c.most_common()[1][1] - one_saihin_val
        print(min(count1, count2))

if __name__ == '__main__':
    main()


Measured memory_bytes: 97992
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    s = list(input())
    N = len(s)
    K = int(input())
    i = 0
    while K > 0:
        if i == N-1:
            num = ord(s[i])+K%26
            if num > ord('z'):
                num -= 26
            s[i] = chr(num)
            break
        else:
            if s[i] != 'a':
                num = 26-ord(s[i])+ord('a')
                if  num <= K:
                    s[i] = 'a'
                    K -= num
            i += 1
    print(''.join(s))

if __name__ == "__main__":
    main()


Measured memory_bytes: 10344
#include<stdio.h>
int n, m, q;
int v[100000][100];
int c[100000];
int g[100000];
int id = 1;

void dfs (int s) {
	int i;
	g[s]=id;
	for (i = 0; i < c[s]; i++) {
		if (g[v[s][i]] == 0)
		dfs(v[s][i]);
	}
}

int main() {
	int i, j, x, y;
	scanf("%d%d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d%d", &x, &y);
		v[x][c[x]++] = y;
		v[y][c[y]++] = x;
	}
	for (i = 0; i < n; i++) {
		if (g[i] == 0) {
			dfs(i);
			id++;
		}
	}
	scanf("%d",&q);
	for (i = 0; i < q; i++) {
		scanf("%d%d", &x, &y);
		if (g[x] == g[y])
		printf("yes\n");
		else printf("no\n");
	}

return 0;
}


Measured memory_bytes: 44604
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
const long long INF=1e18;
int main(){
	int n;
	cin>>n;
	ll ans=1,temp;
	int flag=0;
	for(int i=0;i<n;i++){
		cin>>temp;
		if(temp==0){
			flag=1;
		}
		if(flag==1)	continue;
		if(INF/temp<ans)//将乘法变为除法来判断 
			flag=-1;
		ans*=temp;
	}
	if(flag==1)	puts("0");
	else if(flag==-1)	puts("-1");
	else	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
set<string> a;
int main(){
	int n;
	cin>>n;
	string s[n];
	for(int i=0;i<n;i++)cin>>s[i];
	for(int i=1;i<6;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<s[j].size();k++){
				if(k+i<=s[j].size())a.insert(s[j].substr(k,i));
			}
		}
	}
	for(int i=0;i<27;i++)
		for(int j=0;j<27;j++)
			for(int k=0;k<27;k++)
				for(int l=0;l<26;l++){
					string t;
					if(i)t+='a'-1+i;
					if(j)t+='a'-1+j;
					if(k)t+='a'-1+k;
					t+='a'+l;
					if(!a.count(t)){
						cout<<t<<endl;
						return 0;
					}
				}
}

Measured memory_bytes: 79932
def main():
  N = int(input())
  s = input()
  L = [["S","S"],["S","W"],["W","W"],["W","S"]]
  for i in range(1,N):
    for j in range(4):
      if s[i] == "o":
        if L[j][-1] == "S":
          L[j].append(L[j][-2])
        else:
          if L[j][-2] == "S":
            L[j].append("W")
          else:
            L[j].append("S")
      else:
        if L[j][-1] == "S":
          if L[j][-2] == "S":
            L[j].append("W")
          else:
            L[j].append("S")
        else:
          L[j].append(L[j][-2])
  for i in range(4):
    flg = False
    if L[i][0] != L[i][-1]:
      continue
    if s[0] == "o":
      if L[i][-1] == "S" and L[i][1] == L[i][-2]:
        flg = True
      elif L[i][-1] == "W" and L[i][1] != L[i][-2]:
        flg = True
    else:
      if L[i][-1] == "W" and L[i][1] == L[i][-2]:
        flg = True
      elif L[i][-1] == "S" and L[i][1] != L[i][-2]:
        flg = True
    if flg:
      print(*L[i][:-1],sep="")
      exit()
  print(-1)
main()

Measured memory_bytes: 9532
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

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

        List<String> list = new ArrayList<>();
        for (int i = 0; i < h; i++) {
            String str = sc.next();
            list.add(str);
        }
        sc.close();

        for (int i = 0; i < 100; i++) {
            list = row(list);
            list = column(list);
        }

        for (String line : list) {
            System.out.println(line);
        }
    }

    static List<String> row(List<String> in) {
        List<String> out = new ArrayList<>();
        for (String line : in) {
            if (line.contains("#")) {
                out.add(line);
            }
        }
        return out;
    }

    static List<String> column(List<String> in) {
//        List<String> out = new ArrayList<>();
        if (in.size() == 0) {
//            return out;
            return new ArrayList<>();
        }

        boolean[] deleteTarget = new boolean[in.get(0).length()];
        for (int i = 0; i < in.get(0).length(); i++) {
            boolean target = true;
            for (String line : in) {
                if (line.charAt(i) == '#') {
                    target = false;
                    break;
                }
            }
            if (target) {
                deleteTarget[i] = true;
            }
        }

        List<String> out = in;
        for (int i = deleteTarget.length - 1; i >= 0; i--) {
            final int loc = i;
            if (deleteTarget[i]) {
                out = out.stream().map(e -> {
                    return e.substring(0, loc) + e.substring(loc + 1);
                }).collect(Collectors.toList());
            }
        }
        return out;
    }
}


Measured memory_bytes: 32964
#include <stdio.h>

int main(){
  long d,n;
  long ans = 0;

  scanf("%ld%ld", &d, &n);

  if(d == 0){
    ans = 1*n;
    if(n == 100) ans = 101;
  }
  if(d == 1){
    ans = 100*n;
    if(n == 100) ans = 10100;
  }
  if(d == 2){
    ans = 10000*n;
    if(n == 100) ans = 1010000;
  }

  printf("%ld", ans);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const auto INF = (ll)1e9;
using v = vector<ll>;
using m = map<int,int>;
using vv = vector<v>;

int main(){
    int n;
    cin >> n;
    auto dp = v(n+1,0);
    dp[0] = 2;
    dp[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        dp[i] = dp[i-1] + dp[i-2];   
    }
    cout << dp[n];    
}


Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
using namespace std;
int main(){
	
	vector<int> name;
	set<int> na;
	map<int,int> f;
	map<int,int> s;
	
	while(1){
		string a;
		getline(cin,a);
		if(a=="")
			break;
		string b="";
		for(int i=0;i<a.size();i++){
			if(a[i]!=',')
				b=b+a[i];
			else
				break;
		}
		int k=stoi(b);
		set<int>::iterator it=na.find(k);
		if(it==na.end()){
			na.insert(k);
		name.push_back(k);
		}
		if(f.count(k)==0)
			f[k]=1;
		else
			f[k]++;
	}
	while(1){
		string a;
		getline(cin,a);
		if(a=="")
			break;
		string b="";
		for(int i=0;i<a.size();i++){
			if(a[i]!=',')
				b=b+a[i];
			else
				break;
		}
		int k=stoi(b);
		set<int>::iterator it=na.find(k);
		if(it==na.end()){
			na.insert(k);
		name.push_back(k);
		}
		if(s.count(k)==0)
			s[k]=1;
		else
			s[k]++;
	}
	sort(name.begin(),name.end());
	for(int i=0;i<f.size();i++){
		if(f[name[i]]>=1&&s[name[i]]>=1)
			cout<<name[i]<<" "<<f[name[i]]+s[name[i]]<<endl;
		
	}
	

	
}

Measured memory_bytes: 3188
use whiteread::parse_line;

fn main() {
    let (_n, a, b): (i32, i32, i32) = parse_line().unwrap();
    let s: String = parse_line().unwrap();
    let s = s.as_str().chars();
    let mut pass: i32 = 0;
    // 海外の学生の中の順位
    let mut rank_b: i32 = 0;
    for c in s {
        match c {
            'a' => {
                if pass < a + b {
                    println!("Yes");
                    pass += 1;
                } else {
                    println!("No");
                }
            }
            'b' => {
                rank_b += 1;
                if pass < a + b && rank_b <= b {
                    println!("Yes");
                    pass += 1;
                } else {
                    println!("No");
                }
            }
            'c' => {
                println!("No");
            }
            _ => {
                unreachable!();
            }
        }
    }
}


Measured memory_bytes: 2224
#include <iostream>
using namespace std;
int n, m, p, a[132456], ac, wa[132456], w;
string s;
int main() {
    cin >> n >> m;
    for (int i = 0;i < m;i++) {
        cin >> p >> s;
        if (s == "AC") {
            if (a[p] == 0) {
                ac++;
                a[p]++;
                w += wa[p]++;
            }
        }
        if (s == "WA") {
            if (a[p] == 0)wa[p]++;
        }
    }
    cout << ac << " " << w << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX = 510000;


int main(){
  int N,M;cin>>N>>M;
  vector<int>L(M);
  vector<int>R(M);
  rep(i,M){cin >>L[i]>>R[i];}
  ll ans=0;
  sort(L.begin(),L.end());
  sort(R.begin(),R.end());
  int lma=L[M-1],lmi=R[0];
  if(lmi-lma>=0){ans=1+lmi-lma;}
  cout<<ans;
  
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/e.in", "r", stdin);
//  freopen("../IO/e.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


constexpr int P = 1'000'000'007;
struct edge_t {
  int u, v, w;
  edge_t() = default;
  edge_t(int u, int v, int w) : u(u), v(v), w(w) {}
  bool operator <(const edge_t &rhs) const {
    return this->w < rhs.w;
  }
};
void solve(std::istream &in, std::ostream &out) {
  int n, m;
  int64_t X;
  in >> n >> m >> X;
  vector<vector<edge_t>> adj(n);
  vector<edge_t> edges;
  for (int i = 0, u, v, w; i < m; ++i) {
    in >> u >> v >> w;
    --u;
    --v;
    edges.emplace_back(u, v, w);
    adj[u].emplace_back(v, u, w);
    adj[v].emplace_back(u, v, w);
  }
  vector<int> par(n, -1);
  function<int(int)> find = [&](int x) {
    if (par[x] == -1) return x; else return par[x] = find(par[x]);
  };
  function<bool(int, int)> merge = [&](int u, int v) {
    int x = find(u), y = find(v);
    if (x == y) return false;
    par[x] = y;
    return true;
  };
  sort(edges.begin(), edges.end());
  vector<int> intree(m, 0);
  vector<vector<edge_t>> tree(n);
  int64_t cost = 0;
  for (int i = 0; i < m; ++i) {
    int u = edges[i].u, v = edges[i].v, w = edges[i].w;
    if (merge(u, v)) {
      intree[i] = 1;
      tree[u].emplace_back(v, u, w);
      tree[v].emplace_back(u, v, w);
      cost += w;
    }
  }
  vector<vector<int>> maxcost(n, vector<int>(n, 0));
  function<void(int, int, int, int)> dfs = [&](int u, int p, int root, int mx) {
    maxcost[root][u] = mx;
    for (auto &[v, _, w] : tree[u])
      if (v != p)
        dfs(v, u, root, max(mx, w));
  };
  for (int i = 0; i < n; ++i)
    dfs(i, -1, i, 0);
  vector<int64_t> diff;
  for (int i = 0; i < m; ++i)
    if (!intree[i])
      diff.push_back(edges[i].w - maxcost[edges[i].v][edges[i].u]);
  sort(diff.begin(), diff.end());
  int64_t difference = X - cost;
  vector<int> p2(m + 1, 1);
  for (int i = 1; i <= m; ++i) (p2[i] = 2 * p2[i - 1]) %= P;
  if (difference < 0) {
    out << 0 << '\n';
  } else if (difference == 0) {
    int equal = upper_bound(diff.begin(), diff.end(), (int64_t)0) - diff.begin();
    out << ((int64_t)(p2[n - 1] + P - 2) * p2[m - n + 1] % P + (int64_t) 2 * (p2[equal] + P - 1) * p2[m - (n - 1 + equal)] % P) % P  << '\n';
  } else {
    int lower = lower_bound(diff.begin(), diff.end(), difference) - diff.begin();
    int equal = int(upper_bound(diff.begin(), diff.end(), difference) - diff.begin()) - lower;
    int upper = (int) diff.size() - lower - equal;
    out << (int64_t) 2 * (p2[equal] - 1) * p2[upper] % P << '\n';
  }
}


Measured memory_bytes: 7416
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int a,b,min,i=1,temp=0;
  cin>>a>>b;
  if(a>b){min=b;}
  else {min=a;}
  temp=min;
  while(a%min!=0||b%min!=0){
    i++;
    if(temp%i==0)min=temp/i;
    if(min==1)break;
  }
  cout<<min<<endl;
  return 0;
}



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

int main(){
     int a,b,c,d;
    cin >> a >> b >> c >> d;

//a c b d
//c a b d
//a c d b
//c a d b

    if(a <= c){
        if(c <= b){
            if(b <= d){
                cout << b-c << endl;
             }
            else cout << d-c << endl;
        }
        else cout << "0" << endl;
    }
    else if(c < a){
        if(a <= d){
            if(d <= b){
                cout << d-a << endl;
             }
            else cout << b-a << endl;
        }
        else cout << "0" << endl;
    }

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<i64>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { cout << p.first << ' ' << p.second; return os; }

#define int i64
#define endl '\n'

void solve() {
  int n; cin >> n;
  vi32 a(n); cin >> a;
  
  vi32 sums(n + 1);
  partial_sum(all(a), sums.begin() + 1);
  
  auto inc = [&](int i) { return (i + 1) % n; };
  auto dec = [&](int i) { return (i + n - 1) % n; };

  auto sum = [&](int l, int r) {
    if (l <= r) return sums[r] - sums[l];
    return sums[n] - sums[l] + sums[r];
  };

  auto diff = [&](int l, int m, int r) {
    if (l == m || m == r) return (int) 1e18;
    return abs(sum(l, m) - sum(m, r));
  };

  int ans = 1e18;

  rep(i, 1) {
    int l = inc(i);
    int j = inc(l);
    int r = inc(j);

    for (int e = dec(i); j != e; j = inc(j)) {
      while (diff(i, l, j) > diff(i, l + 1, j)) l = inc(l);
      while (diff(j, r, i) > diff(j, r + 1, i)) r = inc(r);

      auto mm = minmax({
        sum(i, l), sum(l, j), sum(j, r), sum(r, i)
      });
      amin(ans, mm.second - mm.first);
    }
  }

  cout << ans << endl;
}


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

int main(){
  int N;
  int l, r;
  int num = 0;
  
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> l >> r;
    num += r - l + 1;
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int n; cin >> n;
    vector<int> a(n); rep(i,n) cin >> a[i];

    map<int,int> mp;
    vector<map<int,int>> mpx(n);

    rep(i,n){
        int k = a[i];

        for(int j=2; j<=sqrt(a[i])+1; j++){

            if(k %j == 0){
                mpx[i][j]++;
                k /= (j);
                j--;
            }
            if(k == 1) break;
        }
        if(k != 1) mpx[i][k]++;
    }

    rep(i,n){
        for(auto e: mpx[i]){
            if(mp[e.first] < e.second) mp[e.first] = e.second;
        }
    }
    
    ll jud = 1;
    for(auto e: mp){
        rep(_,e.second){
            jud *= e.first;
            jud %= 1000000007;
        }
    }

    ll ans = 0;
    rep(i,n){
        ans += jud * modinv(a[i], 1000000007);
        ans %= 1000000007;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 3072
#include <iostream>

using namespace std;
int n;
unsigned long long s;
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        if (!(i%3==0||i%5==0))
        {
            s+=i;
        }
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cmath>
#include <limits.h>
using namespace std;
typedef long long LL;
const int N=1000;
const LL INF=LLONG_MAX;

int n,u,v;
int d[N],fa[N],c[N],sz[N];
vector<int> gg[N];
bool vis[N];

void bfs(int rt,int rt2) {
	memset(vis,0,sizeof(vis));
	memset(sz,0,sizeof(sz));
	queue<int> que;
	vis[rt]=1;
	d[rt]=0;
	fa[rt]=0;
	que.push(rt);
	if(rt2) {
		vis[rt2]=1;
		d[rt2]=0;
		fa[rt2]=0;
		que.push(rt2);
	}
	while(!que.empty()) {
		u=que.front();que.pop();
		for(int i=0;i<gg[u].size();i++) {
			v=gg[u][i];
			if(vis[v]) continue;
			d[v]=d[u]+1;
			vis[v]=1;
			fa[v]=u;
			sz[u]++;
			que.push(v);
		}
	}
}

int go_up(int u,int t) {
	while(t--) {
		u=fa[u];
	}
	return u;
}

LL cal(int u,int v) {
	bfs(u,v);
	memset(c,0,sizeof(c));
	for(int i=1;i<=n;i++) {
		c[d[i]+1]=max(c[d[i]+1],sz[i]);
	}
	LL res=1;
	c[0]=(v==0)?1:2;
	for(int i=0;i<=n;i++) {
		if(c[i]>0) res*=c[i];
	}
	return res;
}

void solve() {
	bfs(1,0);
	int a1=1,a2;
	for(int i=1;i<=n;i++) {
		if(d[i]>d[a1]) {
			a1=i;
		}
	}
	bfs(a1,0);
	a2=a1;
	for(int i=1;i<=n;i++) {
		if(d[i]>d[a2]) {
			a2=i;
		}
	}
	int ans1=(d[a2]+2)/2;
	LL ans2=INF;
	if(d[a2]&1) {
		int f1=go_up(a2,d[a2]/2);
		int f2=fa[f1];
		ans2=min(ans2,cal(f1,f2));
	}
	else {
		int f=go_up(a2,d[a2]/2);
		ans2=min(ans2,cal(f,0));
		for(int i=0;i<gg[f].size();i++) {
			u=gg[f][i];
			ans2=min(ans2,cal(f,u));
		}
	}
	printf("%d %lld\n",ans1,ans2);
}

int main() {
	scanf("%d",&n);
	for(int i=1;i<n;i++) {
		scanf("%d %d",&u,&v);
		gg[u].push_back(v);
		gg[v].push_back(u);
	}
	solve();
}

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

int main(void){
    int n, m, i, j, k, po=0;
    scanf("%d", &n);
    int a[n], b[n];
    for(i=0; i<n; i++) scanf("%d", &b[i]);
    for(i=0; i<n; i++) a[i] = 0;
    for(i=0; i<n; i++){
        for(j=n-i-1; j>=0; j--){
            if(b[j] == j+1){
                a[i] = j+1;
                for(k=j; k<n-1; k++){
                    b[k] = b[k+1];
                }
                b[n-1] = 0;
                break;
            }
            if(j == 0) po = 1;
        }
        if(po == 1) break;
    }
    if(po == 1) printf("-1");
    else {
        for(i=n; i>0; i--) printf("%d\n", a[i-1]);
    }
//    for(i=0; i<n; i++) printf("%d ", b[i]);

    
    
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
  char ch ;

  while( scanf("%c", &ch) != EOF ){
    if('a' <= ch && ch <= 'z' ){
      printf("%c", ch - 'a' + 'A') ;
    }else if('A' <= ch && ch <= 'Z' ){
      printf("%c", ch - 'A' + 'a') ;
    }else{
      printf("%c", ch) ;
    }
  }
  return 0 ;
}


Measured memory_bytes: 2048
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 100005
#define MAX_E 30005
#define NIL -1
#define WHITE 0
#define BLACK 1
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

vector<ll> G[MAX];
bool visited[MAX];

int main(void) {
    ll N;
    cin >> N;
    ll a[MAX];
    ll i;
    
    for(i=0; i<N; i++) {
        cin >> a[i];
    }
    
    ll ans=0;
    
    for(i=0; i<N; i++) {
        ans+=a[i]/2;
        if(i!=N-1 && a[i]%2==1 && a[i+1]!=0) {
            a[i+1]++;
        }
    }
    prin(ans);
}

Measured memory_bytes: 3328
#include<iostream>
using namespace std;
int main(){

  int A,B;
  int realA,realB;
  cin>>A>>B;
  for(int i=1;i<=2000;i++){
  
    realA=i*0.08;
    realB=i*0.1;
    if(realA==A&&realB==B){
    
      cout<<i;
      return 0;
    }
  }
  cout<<-1;
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>/// important code 3 :   state in 1/0
using namespace std;
int a[109];


int main()
{

    int  n;int x;
    while(~scanf("%d",&n))
    {
        bool flag=1;
        double sum=0,ans=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
        }
        for(int i=0; i<n; i++)
        {
            ans+=a[i];
               if(ans==sum/2)
            {
                flag=0;
                printf("0\n");
                break;
            }
            if(ans>sum/2)
            {
                x=i;
                break;
            }
        }
        int d1=abs(2*ans-2*a[x]-sum);
        int d2=abs(2*ans-sum);
        if(d1<d2&&flag==1)
        {
            printf("%d\n",d1);
        }
        else if(flag==1)
        {
            printf("%d\n",d2);
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int h, w, dx[] = {0,0,-1,1}, dy[] = {1,-1,0,0};
long long a, b, ans;
char s[405][405], t;

void dfs(int x, int y){
  char t;
  ((t = s[x][y]) == '#' ? a : b)++;
  s[x][y] = 0;
  for(int i = 0; i < 4; i++) if((s[x+dx[i]][y+dy[i]] | t) > t) dfs(x+dx[i], y+dy[i]);
}

int main(){
  scanf("%d %d\n", &h, &w);
  for(int i = 1; i <= h; i++){scanf("%s", s[i]+1);s[i][w+1] = 0;}
  for(int i = 1; i <= h; i++) for(int j = 1; j <= w; j++)
    if(s[i][j]) a = b = 0, dfs(i,j), ans += a*b;
  printf("%lld\n", ans);
}

Measured memory_bytes: 7808
#include <iostream>
#include <vector>
#include <set>

using namespace std;

unsigned long long gcd(unsigned long long  a, unsigned long long b) {
	if(b > a) return gcd(b, a);
	
	unsigned long long r = a % b;
	while(r!=0){
    	a = b;
	    b = r;
    	r = a % b;
	}

	return b;
}

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

	std::set<unsigned long long> s;

	for(int i=0; i<N; i++) {
		unsigned long long x;
		cin >> x;
		s.insert(x);
	}

	int size = s.size();

	std::set<unsigned long long>::iterator itr = s.begin();
	unsigned long long ret = *itr;
	itr++;

	while(itr != s.end()) {
		unsigned long long t = *itr;
		unsigned long long g = gcd(ret, t);
		ret = ret / g * t;
		itr++;
	}

	cout << ret << endl;

    return 0;
}




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

int main() {
	int A,B,C,D,P,S,X,Y;
	cin >> A >> B >> C >> D >> P;
	X=A*P;
	if(P<C){
		Y=B;
	}
	else{
		S=P-C;
		Y=B+D*S;
	}
	if(X<Y){
		cout << X << endl;
	}
	else{
		cout << Y << endl;
	}
	return 0;
}

Measured memory_bytes: 3116
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    for(int i=0; i<n; i++) {
      float x1 = sc.nextFloat();
      float y1 = sc.nextFloat();
      float x2 = sc.nextFloat();
      float y2 = sc.nextFloat();
      float m1 = (y2-y1)/(x2-x1);
      x1 = sc.nextFloat();
      y1 = sc.nextFloat();
      x2 = sc.nextFloat();
      y2 = sc.nextFloat();
      float m2 = (y2-y1)/(x2-x1);
      if(m1==m2) {
        System.out.println("YES");
      }
      else {
        System.out.println("NO");
      }
    }
  }
}

Measured memory_bytes: 31924
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

void solve(int N, int K, vector<vector<int>> A) {
    mcf_graph<int64_t, int64_t> graph(2 * N + 2);
    int s = 2 * N, t = 2 * N + 1;

    // s -> row
    for (int r = 0; r < N; r++) {
        graph.add_edge(s, r, K, 0);
    }
    // row -> col
    for (int r = 0; r < N; r++) {
        for (int c = 0; c < N; c++) {
            graph.add_edge(r, N + c, 1, INT_MAX - A.at(r).at(c));
        }
    }
    // col -> t
    for (int c = 0; c < N; c++) {
        graph.add_edge(N + c, t, K, 0);
    }
    graph.add_edge(s, t, N * N, INT_MAX);

    auto res = graph.flow(s, t, N * N);
    vector<string> ans(N, string(N, '.'));
    for (auto&& e : graph.edges()) {
        if (e.from == s || e.to == t || e.flow == 0) continue;
        ans.at(e.from).at(e.to - N) = 'X';
    }

    cout << res.first * INT_MAX - res.second << endl;
    for (int r = 0; r < N; r++) {
        cout << ans.at(r) << endl;
    }
}

int main() {
    int N;
    cin >> N;
    int K;
    cin >> K;
    vector<vector<int>> A(N, vector<int>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A.at(i).at(j);
        }
    }
    solve(N, K, move(A));
    return 0;
}


Measured memory_bytes: 3976
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

int main(){
    int N;
    cin >> N;
    
    vi a(N+10);
    
    int sum = 0;
    rep(i,N) {
        cin >> a[i];
        sum += a[i];
    }
    
    cout << sum - N << endl;
}







Measured memory_bytes: 384
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int N = s.nextInt();
    long power = 1;
    for (int i = 1; i <= N; i++) {
      power = i * power % 1000000007;
    }
    System.out.println(power);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

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

    string s;
    bool f = false;

    cin >> s;

    for (int i = 0; i < s.size(); i++) {

        if (i == 0 && s[i] != 'A') {

            cout << "WA";
            return 0;
        }

        if (s[i] == 'C' && i >= 2 && i <= s.size()-2) {

            if (f) {

                cout << "WA";
                return 0;
            }

            f = true;
            continue;
        }

        if (tolower(s[i]) != s[i] && s[i] != 'A' && s[i] != 'C') {

            cout << "WA";
            return 0;
        }
    }

    if (f == false) cout << "WA";
    else cout << "AC";

    return 0;
}


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

int main(){

	int n;
	int a[10010];
	long long min=1000010, max=-1000010, sum=0;

	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}

	for (int i = 0; i < n; i++){
		if (min>a[i]){
			min = a[i];
		}
		if (max < a[i]){
			max = a[i];
		}
	}

	cout << min <<" "<< max <<" "<< sum << endl;
	

}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    // variable
    ll ans = 0;

    // input
    cout << fixed << setprecision(10);
    int N; cin >> N;
    vector<int> v(N);
    bool ok = true;
    rep(i, N){
        cin >> v[i];
        if(v[i] % 2 == 0){
            if(!(v[i] % 3 == 0 || v[i] % 5 == 0)) ok = false;
        }
    } 

    // solve
    
    if(ok){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256