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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
/*
 * Be careful of overflow
 * Array bounds
 * Assert a!=0 when performing x/a
 * Check base condition for recursion
 * Iterator -> O(1), Element -> O(log n) while using erase
 * 1LL<<x when x>32
 * Be sure of what you are going to code (exception dp)
 * Don't try fancy tricks during contest
 * You can always make a bad round to a good enough round
 */ 
int dx[4]={0,0,-1,1};
int dy[4]={1,-1,0,0};
string grid[1009];
int dis[1009][1009];

void solve()
{
	int h,w;
	cin>>h>>w;
	int sx,sy,Dx,Dy;
	cin>>sx>>sy>>Dx>>Dy;
	sx--;
	sy--;
	Dx--;
	Dy--;
	for(int i=0;i<h;i++)
	cin>>grid[i];
	
	mem(dis,infi);
	deque<pair<pii,int>> q;
	q.push_back({{sx,sy},0});
	dis[sx][sy]=0;
	while(!q.empty())
	{
		auto v = q.front();
		q.pop_front();
		int x = v.fi.fi;
		int y = v.fi.se;
		int dd = v.se;
		if(dd > dis[x][y]) continue;
		
		for(int i=0;i<4;i++)
		{
			int nx=x+dx[i],ny=y+dy[i];
			if(nx<0 || ny<0 || nx>=h || ny>=w || grid[nx][ny]=='#' || dd >= dis[nx][ny]) continue;
			q.push_front({{nx,ny},dd});
			dis[nx][ny]=dd;
		}
		
		for(int i=x-2;i<=x+2;i++)
		for(int j=y-2;j<=y+2;j++)
		{
			if(i<0 || j<0 || i>=h || j>=w || grid[i][j]=='#' || dd+1>=dis[i][j]) continue;
			q.push_back({{i,j},dd+1});
			dis[i][j]=dd+1;
		}
	}
	if(dis[Dx][Dy]==infi) dis[Dx][Dy]=-1;
	cout<<dis[Dx][Dy]<<'\n';
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 8876
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <functional>
using namespace std;

int n, A, B, C, ans;
int l[10], vis[10];

int dfs(int k, int a, int b, int c) {
	if (k == n) {
		if (a == 0 || b == 0 || c ==0) return 1e9;
		return abs(a - A) + abs(B - b) + abs(c - C);
	}
	int ans = 1e9;
	ans = min(ans, dfs(k + 1, a + l[k], b, c) + (a > 0 ? 10 : 0));
	ans = min(ans, dfs(k + 1, a, b + l[k], c) + (b > 0 ? 10 : 0));
	ans = min(ans, dfs(k + 1, a, b, c + l[k]) + (c > 0 ? 10 : 0));
	ans = min(ans, dfs(k + 1, a, b, c));
	return ans;
}

int main() {
	scanf("%d%d%d%d", &n, &A, &B, &C);
	for (int i = 0; i < n; i++) {
		scanf("%d", &l[i]);
	}
	printf("%d", dfs(0, 0, 0, 0));
	return 0;
}

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

#define ll long long
#define pb push_back
vector<int>vc;
int n,dp[100009],m;

int DP(int ind)
{
    if(ind==n-1)return 0;
    if(~dp[ind])return dp[ind];
    int x=abs(vc[ind+1]-vc[ind])+DP(ind+1);
    if(ind+2<n)x=min(x,abs(vc[ind+2]-vc[ind])+DP(ind+2));
        return dp[ind]=x;
}

int main()
{
    ios_base::sync_with_stdio(false);  cin.tie(NULL);
    cin>>n;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)cin>>m,vc.pb(m);
    cout<<DP(0)<<"\n";
    return 0;
}


Measured memory_bytes: 5880
n,a,b,c,d = map(int,input().split())

res = 0
r = b-a
for k in range(1,n):
    s1 = k*c - d *(n-1-k)
    t1 = k*c - c *(n-1-k)
    if s1 <= r and r <= t1:
        res = 1
        break
    
    s1 = k*d - d *(n-1-k)
    t1 = k*d - c *(n-1-k)
    if s1 <= r and r <= t1:
        res = 1
        break

if res == 1:
    print("YES")
else:
    print("NO")

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

int main()
{
	int N;
	cin >> N;
	vector<string> S( N );
	for( int i = 0; i < N; i++ ) {
		cin >> S[i];
	}
	string T;
	cin >> T;

	vector<string> Sa( N );
	for( int i = 0; i < N; i++ ) {
		Sa[i] = S[i];
		if( Sa[i] == T ) Sa[i] = string( T.size(), '?' );
		replace( Sa[i].begin(), Sa[i].end(), '?', 'a'  );
	}
	Sa.push_back( T );
	sort( Sa.begin(), Sa.end() );
	vector<string> Sz( N );
	for( int i = 0; i < N; i++ ) {
		Sz[i] = S[i];
		if( Sz[i] == T ) Sz[i] = string( T.size(), '?' );
		replace( Sz[i].begin(), Sz[i].end(), '?', 'z'  );
	}
	Sz.push_back( T );
	sort( Sz.begin(), Sz.end() );
	int f = find( Sa.begin(), Sa.end(), T ) - Sa.begin();
	int e = find( Sz.begin(), Sz.end(), T ) - Sz.begin();
	vector<int> ans;
	for( int i = e; i <= f; i++ ) {
		ans.push_back( i + 1 );
	}


	for( int i = 0; i < ans.size(); i++ ) {
		if( i ) cout << " ";
		cout << ans[i];
	}
	cout << endl;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const double eps = 1e-5;
int n,d,ans = 0;
struct Point{
    double x[12];
}p[12];
bool calc(Point a,Point b){
    double t = 0;
    for(int i = 0;i < d; ++i){
        t += (a.x[i] - b.x[i]) * (a.x[i] - b.x[i]);
    }
    t = sqrt(t);
    if(fabs(t - (int)t)< eps) return 1;
    else return 0;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin >> n >> d;
    for(int i = 0;i < n; ++i){
        for(int j = 0;j < d; ++j){
            cin >> p[i].x[j];
        }
    }
    for(int i = 0;i < n; ++i){
        for(int j = i+1;j < n; ++j){
            if(i == j) continue;
            if(calc(p[i],p[j])) ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>

using namespace std;

int main()
{
	int m, k, f;
	while(true) {
		cin >> m >> k >> f;
		if(m == -1 && k == -1 && f == -1)
			break;

		if(m == -1 || k == -1)
			cout << "F" << endl;
		else if(m + k >= 80)
			cout << "A" << endl;
		else if(m + k >= 65)
			cout << "B" << endl;
		else if(m + k >= 50)
			cout << "C" << endl;
		else if(m + k >= 30) {
			if(f >= 50)
				cout << "C" << endl;
			else
				cout << "D" << endl;
		}
		else
			cout << "F" << endl;
	}
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n-1); 0=<i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);

int main(void){
    double A,B,H,M;

    cin >> A >> B >> H >> M;

    //時針と分針がなす角度thetaを求める
    //時：12時間＝720分で一周=2pi/720=分速pi/360
    //分：60分で一周：2pi/60=分速pi/30
    double theta = 0;
    double H_w = M_PI / (double)360;
    double M_w = M_PI / (double)30;

    //角度計算(分の分、H_wも進むことに注意)
    theta = M*M_w - H_w*( H*60 + M );

    //cout << cos(theta) << endl;

    //余弦定理で距離を算出する
    double C = 0;
    C = sqrtl( A*A + B*B - 2*A*B*cos(theta) );

    cout << fixed;
    cout << setprecision(9) << C << endl;

    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < (int)(n); i++)
using ull = unsigned long long;
using ll = long long;


int main() {
    ll N, K;
    cin >> N >> K;

    ll A[N], ai;
    rep(i, N) {
        cin >> ai;
        A[i] = ai - 1;
    }

    ll pre_loop_num = 0;
    ll loop_start_i, loop_num = 0;
    bool first_visited = false, second_visited = false;
    ll visited[N];
    rep(i, N) visited[i] = 0;
    ll now = 0;

    while (!second_visited) {
        visited[now]++;
        if (visited[now] == 3) {
            second_visited = true;
            break;
        }    
        if (visited[now] == 2) {
            if (!first_visited) {
                first_visited = true;
                loop_start_i = now;
            }
            loop_num++;
        } 
        if (visited[now] == 1) pre_loop_num++;

        now = A[now];
    }

    now = 0;
    if (K >= pre_loop_num) {
        now = loop_start_i;
        K -= pre_loop_num;
        K %= loop_num;
    }

    rep(i, K) now = A[now];
    cout << now + 1 << endl;
    
    return 0;
}

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

int main() {
    long long n, d, x, y, max = 0;
    scanf("%lld%lld", &n, &d);

    for (int i = 0; i < n; ++i) {
        scanf("%lld%lld", &x, &y);

        if ((sqrt(x * x + y * y)) <= d)
            ++max;
    }
    
    printf("%d", max);
    
    return 0;
}

Measured memory_bytes: 2156
import java.util.Scanner;

public class Main
{
    //RMQ in aizu
    //refernece https://blog.csdn.net/u013174702/article/details/44161821
    //size 4*maxn
    static int maxN = 100005;
    static int size = 4*maxN;//segment tree
    static int tree[] = new int[size];//start from 0
    public static void main(String[] args) {
        int n,q;
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        q = in.nextInt();
        int N = 1;
        while(N<n){
            N = N<<1;
        }
        //init tree
        //System.out.println(N);
        for(int i = 0; i<size; i++) tree[i] = 0x7fffffff;
        //System.out.println(tree[0]);
        //the number of max leaf
        if(N==1) N = 2;
        for(int i = 0; i<q; i++){

            int num1 = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();
            if(num1==0){
                update(a,a,0,N-1,b,0);
            }else if(num1==1){
                int res = query(a,b,0,N-1,0);
                System.out.println(res);
            }

        }

    }

    private static int query(int L, int R, int l, int r, int node) {
        if(l>R || r<L) return 0x7fffffff;//or mid
        if(l>=L && r<=R){
            return tree[node];
        }
        int p = query(L,R,l,(l+r)/2,node*2+1);
        int q = query(L,R,(l+r)/2+1,r,node*2+2);

        return Math.min(p,q);
    }

    //node stores min value
    //node correspond to l and r
    private static void update(int L, int R, int l, int r, int val,int node) {
        if(l>R || r<L) return;//or mid
        if(l>=L && r<=R){
            tree[node] = val;
            return;
        }
        int mid = (l+r)/2;
        //System.out.println(node+" "+l+" "+r);
        update(L,R,l,mid,val,node*2+1);
        update(L,R,mid+1,r,val,node*2+2);
        //push up
        if(tree[node*2+1]<tree[node*2+2]) tree[node] = tree[node*2+1];
        else tree[node] = tree[node*2+2];
    }
}



Measured memory_bytes: 112224
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)

using namespace std;

typedef long long LL;

const int INF=0x3f3f3f3f;

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    if(b>=a)puts("unsafe");
    else puts("safe");
    return 0;
}

Measured memory_bytes: 3688
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		String input_number = ""; // 入力数
		String input_string = "";
		int n = 0; // 入力数を数値に変換するための変数
		Scanner sc = new Scanner(System.in);
		int[][][] school_data = new int[4][3][10]; // 大学の各棟の各階の各フロアの人数情報
													// ex)[0][2][5]→1棟の3階の6番目の部屋の人数
		String split_Line = "####################";
		String[] array_input = new String[4];
		int tenant = 0; // 棟の番号
		int floor = 0; // 何階かを示す変数
		int room = 0; // 部屋の番号
		int people = 0; // 各部屋にいる人の人数
		boolean judge = true; // 入力された値が条件範囲内かどうかを判定するときに使う変数
		String output_school_data = "";

		input_number = sc.nextLine();
		n = Integer.parseInt(input_number);

		out: for (int i = 0; i < n; i++) {
			input_string = sc.nextLine();
			array_input = input_string.split(" ");
			tenant = Integer.parseInt(array_input[0]);
			floor = Integer.parseInt(array_input[1]);
			room = Integer.parseInt(array_input[2]);
			people = Integer.parseInt(array_input[3]);

			if ((tenant < 1 || tenant > 4)
					|| (floor < 1 || floor > 13)
					|| (room < 1 || room > 10)
					|| (school_data[tenant - 1][floor - 1][room - 1] < 0 || school_data[tenant - 1][floor - 1][room - 1] > 9)) {
				judge = false;
				break out;
			}
			school_data[tenant - 1][floor - 1][room - 1] += people;

		}

		if (judge == true) {
			for (int j = 0; j < school_data.length; j++) { // 棟
				for (int k = 0; k < school_data[0].length; k++) {// 階
					output_school_data = "";
					for (int m = 0; m < school_data[0][0].length; m++) {// 部屋
						output_school_data += " " + school_data[j][k][m];
					}
					System.out.println(output_school_data);
				}
				if (j != school_data.length - 1) {
					System.out.println(split_Line);
				}
			}
		}

	}
}



Measured memory_bytes: 27092
import sys
from itertools import permutations

inputs = []

for _ in range(5):
    inputs.append(int(sys.stdin.readline()))
k = int(sys.stdin.readline())


flag = True
for i, j in permutations(inputs, 2):
    if abs(i - j) > k:
        flag = False
        break

if flag:
    print('Yay!')
else:
    print(':(')

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

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

int main(){
	string s;
	cin>>s;
	ll siz = s.size();
	ll ans = 0LL;
	ll cnt_b = 0;
	for(int i = s.size()-1; i>=0; --i){
		if(s[i] == 'B'){
			ans += siz-i-1-cnt_b;
			++cnt_b;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
n = int(input())
t,a = [int(i) for i in input().split()]

h = [int(i) for i in input().split()]

cand = float('inf')
ans = 1

for i in range(n):
    temp = abs(a - (t - 0.006*h[i]))
    if cand > temp:
        cand = temp 
        ans = i+1
        
print(ans)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(obj) (obj).begin(), (obj).end()

int main(){
	string S;
	cin >> S;
	if((S[5] == '1')||(S[6] >= '5')){
		printf("TBD\n");
	}else{
		printf("Heisei\n");
	}
	
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  int n,m,k;
  cin >> n >> m >> k;
  R(i,n+1)R(j,m+1){
    int pom = i * (m - j) + j * (n - i);
    if(pom == k){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int MaxN = 1e5 + 5;
int n,m,i,j,k,ans;
int a[MaxN];
int main(){
	while(~scanf("%d%d",&n,&m)){
		ans = (n-1)*(m-1);
		printf("%d\n",ans);
		}
	}


Measured memory_bytes: 128
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

int64_t N, D;
std::vector<int64_t> X, Y;

void solve()
{
    std::cin >> N >> D;
    X.resize(N);
    Y.resize(N);
    for (int64_t i = 0; i < N; i++) std::cin >> X[i] >> Y[i];

    int64_t ans = 0;
    for (int64_t i = 0; i < N; i++)
    {
        if (X[i] * X[i] + Y[i] * Y[i] <= D * D) ans++;
    }

    std::cout << ans << std::endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}


Measured memory_bytes: 6340
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    Int(n);
    int ret = 0;
    rep(i, n) {
        Int(tmp);
        ret += tmp % 2;
    }
    cout << ((ret % 2) ? "NO" : "YES" ) << endl;



    return 0;
}



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

int main(){
    int K = 26;
    int D;
    cin >> D;
    vector<ll> C(K);
    for (int i = 0; i < K; i++) cin >> C[i];
    vector<vector<ll>> s(D+1, vector<ll>(K, 0));
    for (int i = 1; i <= D; i++) {
        for (int j = 0; j < K; j++) {
            cin >> s[i][j];
        }
    }
    
    vector<int> ans(D+1, 0);
    
    vector<set<int>> day(K);
    for (int i = 0; i < K; i++) {
        day[i].insert(0);
        day[i].insert(D+1);
    }
    vector<int> cnt(K, 0);
    for (int i = 1; i <= D; i++) {
        int op = 0;
        int s_mx = 0;
        for (int j = 0; j < K; j++) {
            if (s_mx < s[i][j]) {
                s_mx = s[i][j];
                op = j;
            }
        }
        day[op].insert(i);
        ans[i] = op+1;
    }
    
    for (int i = 1; i <= D; i++) cout << ans[i] << endl;
    
    return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;


int main() {
    string s; cin>>s;
    int count=0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='o'){
            count++;
        }
    }
    int nokori =0;
    nokori=15-s.size();
    if(count+nokori>=8){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String [] args)
    {
        Scanner key = new Scanner(System.in);
        int num = key.nextInt();
        long sum = 0;
        int a = 1;
        int b = 1;
        int c = 1;
        for(int i =1; i<=num ; i++)
        {
            for(int j = 1 ; j<=num ; j++)
            {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 36064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int calculate_gcd(ll a, ll b){
    if(a<b){swap(a,b);}
    if(b<1){return 0;}
    ll r;
    while((r = a%b) != 0){
        a = b;
        b = r;
    }
    return b;
}


int main() {
    ll n, X;
    cin >> n >> X;
    vector<ll> x(n+1);
    vector<ll> diff(n);
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    x[n] = X;
    sort(x.begin(),x.end());
    for(int i = 0; i < n; i++){
        diff[i] = x[i+1] - x[i];
    }

    ll val = diff[0];
    for(int i = 1; i < n; i++){
        val = calculate_gcd(val, diff[i]);
    }

    cout << val << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <queue>

using namespace std;

#define pb push_back
#define pbk pop_back
#define fs first
#define sc second
#define sz(s) ((int) (s).size())
#define all(x) (x).begin(), (x).end()
#define mt make_tuple
#define mp make_pair
#define next hunext
#define prev huprev

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long double ld;

const int inf = 1e9;
const double pi = 4 * atan(1.0);
const double eps = 1e-9;
const int N = 111;

int a[N];

inline int sqr(int x) {
    return x * x;
}

int main() {
#ifdef LOCAL42
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    int ans = inf;
    for (int i = -100; i <= 100; ++i) {
        int sum = 0;
        for (int j = 0; j < n; ++j) {
            sum += sqr(a[j] - i);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
class UnionFindTree
    def initialize(n)
        @par=[*0...n]
        @rank=[0]*n
    end
    def root(x)
        x==@par[x] ? x : @par[x]=root(@par[x])
    end
    def unite(x, y)
        x=root(x);
        y=root(y);
        if @rank[x]<@rank[y]
            @par[x]=y;
        else
            @par[y]=x;
            @rank[x]+=1 if @rank[x]==@rank[y]
        end
    end
    def same?(x, y)
        root(x)==root(y)
    end
end


n, m=gets.split.map &:to_i
l=[]
n.times{|i| _, *l[i]=gets.split.map{|e|e.to_i-1} }

a=UnionFindTree.new(1e5)
l.each{|v| v.each{|x| a.unite(x, v[0])}}
puts (l.each_cons(2).all?{|x, y| a.same?(x[0], y[0])} ? :YES : :NO)

Measured memory_bytes: 12084
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	ll n, k; cin >> n >> k;
	vector<ll> A;
	vector<pair<ll,ll>> LR;
	rep(i,0,k){
		ll a,b; cin >> a >> b;
		LR.push_back(make_pair(a, b));
		rep(j, a, b + 1){
			A.push_back(j);
		}
	}

	vector<ll> dp(200010,0);
	dp[1]++;

	rep(i, 1, n + 10){
		if(i != 2) dp[i] = (dp[i - 1] % MOD + dp[i] % MOD) % MOD;
		if(dp[i] >= 1){
			for(auto p : LR){
				ll l = p.first;
				ll r = p.second;
				if(l + i <= n + 10){
					dp[l + i] = ((dp[l + i] + (dp[i] % MOD)) % MOD + MOD) % MOD;
				}
				if(r + i <= n + 10){
					dp[r + i + 1] = ((dp[r + i + 1] - (dp[i] % MOD)) % MOD + MOD) % MOD;
				}
			}
		}
	}

	/* rep(i,1,n + 1){
		debug(dp[i]);
	}
	*/
	
	ll ans = (dp[n] % MOD + MOD) % MOD;
	cout << ans << endl;
	

}

Measured memory_bytes: 6296
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a,b,c,d;
	while(true){
	cin>>n;
	c=0,d=0;
	if(n==0)
		break;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		if(a>b)
			c+=a+b;
		if(a<b)
			d+=a+b;
		if(a==b){
			c+=a;
			d+=b;
		}
	}
	cout<<c<<" "<<d<<endl;
	}
    return 0;
}
 

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

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

    ll A[N];
    for(ll i = 0; i < N; i++){
        cin >> A[i];
    }

    ll ans = 0;

    for(ll i = 1; i < N; i++){
        if(A[i-1] > A[i]){
            ans += A[i-1] -A[i];
            A[i] = A[i-1];     
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5208
module Main where

import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [_, _, x, y] <- fmap read . words <$> getLine :: IO [Int]
    xs <- fmap read . words <$> getLine :: IO [Int]
    ys <- fmap read . words <$> getLine :: IO [Int]
    let maxx = maximum xs
    let miny = minimum ys
    let zs = [maxx + 1 .. miny]
    let nowar = any (\z -> x < z && z <= y) zs
    if nowar
        then putStrLn "No War"
        else putStrLn "War"

Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

int main(){
    int N, X;
    cin >> N >> X;
    vector<int> m(N);
    for (auto& x : m) cin >> x;

    int S = accumulate(m.begin(), m.end(), 0);
    int min = *min_element(m.begin(), m.end());
    cout << N + (X - S) / min << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
std::vector<int> v;


int32_t main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","rb",stdin);
    // #endif
int a,b,k;
cin >> a >> b >> k;
int cnt = 0;
for(int i=1;i<110;i++){
   if(a%i==0&&b%i==0){
     v.push_back(i);
   }
}
reverse(v.begin(),v.end());

cout << v[k-1] ;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <math.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 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<ll,int> P;
//typedef pair<int,P> PP;

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

int w,h;
ll ans;
vector<P> v;

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

	cin>>w>>h;
	int tmp;
	REP(i,w) {
		cin>>tmp;
		v.pb(P(tmp,0));
	}
	REP(i,h) {
		cin>>tmp;
		v.pb(P(tmp,1));
	}
	sort(v.begin(),v.end());
	h++,w++;
	for(auto u:v) {
		if(u.se==0) ans+=u.fi*h,w--;
		else ans+=u.fi*w,h--;
		//cout<<"u.fi="<<u.fi<<",u.se="<<u.se<<",ans="<<ans<<endl;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 6512
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s[3];
  while (cin >> s[0] >> s[1] >> s[2]) {
    int index[3] = { 0, 0, 0 };
    int t = 0;
    
    while (true) {
      if (index[t] == s[t].size()) {
	cout << (char)(t + 'A') << endl;
	break;
      }

      int next = s[t][index[t]] - 'a';
      index[t]++;
      t = next;
    }
  }
}


Measured memory_bytes: 256
import std;
import core.bitop;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "B", long, "W");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

class UnionFind
{
    long n;
    long[] par;

    this(long init)
    {
        n = init;
        par = iota(n).array();
    }

    long root(long x)
    {
        if (par[x] == x)
            return x;
        else
            return par[x] = root(par[x]);
    }

    void unit(long x, long y)
    {
        if (root(x) != root(y))
            par[root(x)] = root(y);
    }

    bool same(long x, long y)
    {
        return (root(x) == root(y));
    }
}

void main()
{
    long h, w;
    scan(h, w);
    auto s = new string[](h);
    s.each!((ref x) => x = sread());

    long convIdx(long x, long y)
    {
        return x * w + y;
    }

    auto uf = new UnionFind(h * w);
    foreach (i; iota(h))
    {
        foreach (j; iota(w))
        {
            if (i - 1 >= 0 && s[i - 1][j] != s[i][j])
                uf.unit(convIdx(i - 1, j), convIdx(i, j));

            if (i + 1 < h && s[i + 1][j] != s[i][j])
                uf.unit(convIdx(i + 1, j), convIdx(i, j));

            if (j - 1 >= 0 && s[i][j - 1] != s[i][j])
                uf.unit(convIdx(i, j - 1), convIdx(i, j));

            if (j + 1 < w && s[i][j + 1] != s[i][j])
                uf.unit(convIdx(i, j + 1), convIdx(i, j));
        }
    }
    Pair[long] countBW;
    foreach (i; iota(h))
    {
        foreach (j; iota(w))
        {
            auto idx = uf.root(convIdx(i, j));
            auto p = Pair(s[i][j] == '#', s[i][j] == '.');
            if (idx in countBW)
                countBW[idx] = Pair(countBW[idx].B + p.B, countBW[idx].W + p.W);
            else
                countBW[idx] = p;
        }
    }

    long ans;
    foreach (key, value; countBW)
        ans += value.B * value.W;

    ans.writeln();
}

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


Measured memory_bytes: 20104
// AGC 13 A
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(){
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    int c = 1;
    bool plus = false, minus = false;
    for(int i = 1; i < n; i++){
        if(a[i-1] == a[i]){
            continue;
        }else{
            if(a[i-1] < a[i]){
                // 増加
                plus = true;
                if(minus){
                    c++;
                    plus = false;
                    minus = false;
                }
            }else{
                // 減少
                minus = true;
                if(plus){
                    c++;
                    plus = false;
                    minus = false;
                }
            }
        }
    }
    cout << c << endl;

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
 
using namespace std;
 
int W,H;
typedef long long ll;
 
int p[100005],q[100005]; 
ll sp[100005],sq[100005];
ll ans;
 
int main(){
 
	cin>>W>>H;
 
	for(int i=0; i<W; i++) scanf("%d",&p[i]);
	
	for(int i=0; i<H; i++) scanf("%d",&q[i]);

	sort(p,p+W); sort(q,q+H);

	sp[0]=p[0]; sq[0]=q[0];

	for(int i=1; i<W; i++){
		sp[i]=sp[i-1]+p[i];
	}

	for(int i=1; i<H; i++){
		sq[i]=sq[i-1]+q[i];
	}

	int x=W-1,y=H-1;

	while(1){
		if(p[x]>q[y]){
			ans+=p[x]+sq[y]; x--;
		}else{
			ans+=q[y]+sp[x]; y--;
		}
		if(x<0){
			ans+=sq[y]; break;
		}
		if(y<0){
			ans+=sp[x]; break;
		}
	}
 
	cout<<ans<<endl;
 
	return 0;
 
}

Measured memory_bytes: 2560
#include<stdio.h>

int main(void)
{
    char text[7];

    scanf("%s", text);

    if (text[2] == text[3])
    {
        if(text[4] == text[5])
        {
            printf("Yes\n");
        }
        else
            printf("No\n");
    }
    else
        printf("No\n");

    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
  int N;
  cin >> N;
  
  double ans = 0.0;
  rep(i, N) {
    double x;
    string u;
    cin >> x >> u;
    if(u=="JPY") {
      ans += x;
    } else {
      ans += x*380000.0;
    }
  }

  std::cout<<std::fixed<<std::setprecision(10);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
// ABC143C2.cpp :

//#include "pch.h"
#include <iostream>
#include <vector>
#include <string>

using namespace std;
int main()
{
	int N;
	cin >> N;
	string S;
	cin >> S;
	S = S + 'Z';
	char TMP = S.at(0);
	int ans = 0;
	for (int i = 1; i <= N; i++)
	{
		if (TMP!=S.at(i))
		{
			TMP = S.at(i);
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <iterator>
#include <vector>
#include <unordered_map>
#include <algorithm>

struct pair_hash {
	template <class T1, class T2>
	std::size_t operator() (const std::pair<T1, T2> &pair) const {
		return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
	}
};

int main()
{
  int a, b;
  std::cin >> a >> b;
  int res = 0;
  if (a > b) {
    if (a-1 > b) res = 2*a - 1;
    else res = a + b;
  }
  else {
    if (a > b-1) res = a + b;
    else res = 2*b - 1;
  }
  std::cout << res;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
	(void)argc;
	(void)argv;
	int N;
	scanf("%d",&N);

	char s[16] = {};
	sprintf(s,"%d",N);
	if (s[0]==s[2]) {printf("Yes\n");}else{printf("No\n");}

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define psb push_back
#define ppb pop_back

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

int main() {
    int N, Q;
    cin >> N;

    map<ll,ll> a;
    rep (i, N) {
        ll n = 0;
        cin >> n;
        a[n]++;
    }

    cin >> Q;

    ll sum = 0;
    for (const auto [k,v] : a) sum += k*v;

    vl ans;
    rep (i, Q) {
        ll b, c;
        cin >> b >> c;

        if (!a.count(b)) {
            ans.psb(sum);
            continue;
        }

        ll v = a[b];
        sum -= b*v;
        a.erase(b);
        a[c] += v;
        sum += c*v;

        ans.psb(sum);
    }

    for (const auto n : ans) cout << n << endl;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int r, g, b;
bool flag = false;

void dfs(vector<int> &A, int k) {
    if (A.size() == k) {
        int rt = r;
        int rg = g;
        int rb = b;
        
        rep(i, k) {
            if(A.at(i) == 0) {
                rt *= 2;
            }
            if(A.at(i) == 1) {
                rg *= 2;
            }
            if(A.at(i) == 2) {
                rb *= 2;
            }
        }
        if(rb > rg && rg > rt) {
            flag = true;
        }
        return;
    }

    for (int v = 0; v < 3; ++v) {
        A.push_back(v);
        dfs(A, k);
        A.pop_back();
    }
}

int main(){
    int k;
    cin >> r >> g >> b;
    cin >> k;
    vector<int> A;
    dfs(A, k);
    if(flag) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int m,int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(m,n / 2);
	x *= x;
	if (n % 2 == 1)x *= m;
	return x;
}
ll max(ll a, ll b) {
	if (a < b)return b;
	else return a;
}

int main() {
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	int x = n,y=n;
	hei(int) st;
	for (int i = n; i >= 0; i--) {
		if (s[i] == '0')y = i;
		if (x - i >= m) {
			if (y == x) {
				cout << -1 << endl;
				return 0;
			}
			st.push_back(x - y);
			x = y;
		}
	}
	if (x != y)st.push_back(x - y);
	reverse(st);
	rep(i, 0, st.size()) {
		cout << st[i];
		if (i == st.size() - 1)cout << endl;
		else cout << " ";
	}
	return 0;
}

Measured memory_bytes: 1144
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int main(){
  int player_num;
  int consective_win_num;
  int case_idx = 1;
  while(~scanf("%d %d",&player_num,&consective_win_num)){
    if(player_num == 0 && consective_win_num == 0) break;

    int winners[21];
    memset(winners,0,sizeof(winners));
    winners[0] = player_num;
    
    int res = 0;
    for(int turn = 1;winners[consective_win_num] < 1;turn++){

      int next_winners[21];
      memset(next_winners,0,sizeof(next_winners));

      for(int win=0;win<player_num;win++){
	next_winners[win+1] += winners[win] / 2;
	next_winners[win] += winners[win] % 2;
	next_winners[0] += winners[win] / 2;
      }

      memcpy(winners,next_winners,sizeof(int)*21);
      res = turn;
    }

    printf("Case %d: %d\n",case_idx,res);
    case_idx++;
  }
}

Measured memory_bytes: 1188
#include <iostream>

using namespace std;
int main(){
	int buf;
	int count = 0;
	int X, Y;
	cin >> X >> Y;
	bool flag = false;
	count = X * 2;
	for (int i = 0; i <= X; i++) {
		buf = count + i * 2;
		if (buf == Y) {
			flag = true;
			break;
		}
	}
	if (flag)cout << "Yes";
	else cout << "No";

}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int ziki(char ch){
	if(ch=='^'||ch=='U')return 1;
	if(ch=='v'||ch=='D')return 3;
	if(ch=='<'||ch=='L')return 4;
	if(ch=='>'||ch=='R')return 2;
	return 0;
}
char vec[]=".^>v<";
int px[]={0,0,1,0,-1};
int py[]={0,-1,0,1,0};

int main(){
	int t;
	for(cin>>t;t>0;t--){
		
		
		int h,w,n,v;
		int x,y;
		cin>>h>>w;
		char map[22][22];
		for(int i=0;i<22;i++)for(int j=0;j<22;j++)map[j][i]='#';
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				cin>>map[j][i];
				if(ziki(map[j][i]))x=j,y=i,v=ziki(map[j][i]),map[j][i]='.';
			}
		}
		char c;
		for(cin>>n;n>0;n--){
			cin>>c;
			if(c=='U')if(y>1)if(map[x][y-1]=='.')y--;
			if(c=='D')if(y<h)if(map[x][y+1]=='.')y++;
			if(c=='L')if(x>1)if(map[x-1][y]=='.')x--;
			if(c=='R')if(x<w)if(map[x+1][y]=='.')x++;
			
			if(c=='S'){
				for(int X=x+px[v],Y=y+py[v];1;X+=px[v],Y+=py[v]){
					if(map[X][Y]=='#')break;
					if(map[X][Y]=='*'){
						map[X][Y]='.';
						break;
					}
				}
			}
			else v=ziki(c);
			/*
			cout<<x<<" "<<y<<" "<<c<<endl;
			for(int i=0;i<=h+1;i++){
				for(int j=0;j<=w+1;j++){
					if(j==x&&i==y)cout<<vec[v]<<(j==w+1?"\n":"");
					else cout<<map[j][i]<<(j==w+1?"\n":"");
					
				}
			}
			*/
		}
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				if(j==x&&i==y)cout<<vec[v]<<(j==w?"\n":"");
				else cout<<map[j][i]<<(j==w?"\n":"");
				
			}
		}
		
		if(t!=1)cout<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1156
#include <iostream>
#include <vector>

int main(){
  int n;
  std::cin >> n;
  std::vector<int> p;
  int temp;
  while(std::cin >> temp)
    p.push_back(temp);
  int cnt = 0;
  for(int i=0; i<n; ++i)
    if(p[i] != i+1)
      ++cnt;
  if(cnt>2)
    std::cout << "NO" << std::endl;
  else
    std::cout << "YES" << std::endl;
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    readLine()
    val (t, a) = readLine()!!.split(" ").map(String::toInt)
    val h = readLine()!!.split(" ").map { Math.abs(t - it.toInt() * 0.006 - a) }
    print(h.indexOfFirst { it == h.min() } + 1)
}

Measured memory_bytes: 37872
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
void solve(string s)
{
    string res = "";
    ll ans = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] != res.back() && res.size() > 0)
        {
            ans += 2;
            res.pop_back();
        }
        else
        {
            res += s[i];
        }
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    solve(s);
    return 0;
}



Measured memory_bytes: 720
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class segtree{
public:
	static const int N=1<<19;
	int dp[1<<20];
	int lazy[1<<20];
	segtree(){
		memset(dp,0,sizeof(dp));
	}

	void lazy_eval(int k){
		dp[k]+=lazy[k];
		if(k<N-1){
			lazy[k*2+1]+=lazy[k];
			lazy[k*2+2]+=lazy[k];
		}
		lazy[k]=0;
	}
	void lazy_upd(int k){
		dp[k]=max(dp[k*2+1],dp[k*2+2]);
	}
	void update(int a,int b,int v,int k=0,int l=0,int r=N){
		lazy_eval(k);
		if(b<=l || r<=a)return;
		if(a<=l && r<=b){
			lazy[k]+=v;
			lazy_eval(k);
			return;
		}
		int mid=(l+r)/2;
		update(a,b,v,k*2+1,l,mid);
		update(a,b,v,k*2+2,mid,r);
		lazy_upd(k);
		return;
	}

	int query(int a,int b,int k=0,int l=0,int r=N){
		lazy_eval(k);
		if(b<=l || r<=a)return -214514;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		int vl=query(a,b,k*2+1,l,mid);
		int vr=query(a,b,k*2+2,mid,r);
		lazy_upd(k);
		return max(vl,vr);
	}
};

segtree seg;

int n,q;
int b[200002];
int sum[200002];
P p[200002];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&b[i]);
		sum[i+1]+=sum[i];
		sum[i+1]+=b[i];
		seg.update(i+1,n+1,-b[i]);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		scanf("%d%d",&p[i].first,&p[i].second);
		p[i].first--;
	}
	sort(p,p+q);
	int now=0;
	for(int i=0;i<n;i++){
		while(now<q && p[now].first==i){
			int v=seg.query(0,p[now].second);
			int prev=seg.query(p[now].second,p[now].second+1)+sum[p[now].second]-sum[i];
			seg.update(p[now].second,p[now].second+1,max(v+sum[p[now].second]-sum[p[now].first]-prev,0));
			now++;
		}
		int prev=seg.query(i+1,i+2)+b[i];
		if(b[i]==0){
			seg.update(i+1,i+2,max(seg.query(i,i+1)-prev+1,0));
		}else{
			seg.update(i+1,i+2,max(seg.query(i,i+1)-prev,0));
		}
		seg.update(i+1,n+1,b[i]);
	}
	printf("%d\n",n-seg.query(n,n+1));
	return 0;
}

Measured memory_bytes: 10624
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n;
ll a[200200];
ll s;

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

    ll x = a[0];
    ll ans = abs(2ll * x - s);
    for(int i = 1; i < n; ++i){
        ans = min(ans, abs(2ll * x - s));
        x += a[i];
    }
    return ans;
}

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

    cout << solve() << "\n";
    
    return 0;
}


Measured memory_bytes: 1792
N,D = gets.chomp.split.map(&:to_i)
XY = N.times.map{gets.chomp.split.map(&:to_i)}
count = 0

(0...N).each do |i|
  if ((XY[i][0]**2) + (XY[i][1]**2)) <= D**2
    count += 1
  end
end

puts count

Measured memory_bytes: 28536
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <string>
#define rep(i,beg,end) for(int i=(beg);i<(end);i++)
typedef long long LL;
using namespace std;

int n,num[4];
double dp[301][301][301];
double dfs(int a,int b,int c){
	if(a==0&&b==0&&c==0)return 0;
	//cout<<a<<" "<<b<<" "<<c<<endl;
	if(dp[a][b][c]>0)return dp[a][b][c];
	double ret=1.0*n/(a+b+c);
	if(a>0)ret+=dfs(a-1,b,c)*a/(a+b+c);
	if(b>0)ret+=dfs(a+1,b-1,c)*b/(a+b+c);
	if(c>0)ret+=dfs(a,b+1,c-1)*c/(a+b+c);
	return dp[a][b][c]=ret;
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;
		num[tmp]++;
	}
	cout<<std::fixed<<setprecision(10)<<dfs(num[1],num[2],num[3])<<endl;
	return 0;
}


Measured memory_bytes: 111124
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    ll n,m; cin >> n >> m;
    if(2*n <= m) cout << n+(m-n*2)/4 << endl;
    else cout << m/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<algorithm>
#include<cstdio>
#define N 100005
using namespace std;
struct ab{
int a,b;
};
ab a[N];
int cmp(ab x,ab y){
return x.a<y.a;
}
int n;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i].a);
a[i].b=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
printf("%d ",a[i].b);
}
}

Measured memory_bytes: 2504