akhauriyash/Code-Regression huggingface dataset:
N,M = (list(map(int,input().split())))
S = input()
T = input()

def gcd(x,y):
    x,y = min(x,y),max(x,y)
    if y%x == 0:
        return x
    return gcd(x,y%x)
    
def main():
    if S[0] != T[0]:
        return -1
    g = gcd(N,M)
    n = N//g
    m = M//g
    for i in range(g):
        if S[n*i] != T[m*i]:
            return -1
    return N*M//g

print(main())

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (1) {
        int M, T, P, R;
        cin >> M >> T >> P >> R;
        if (!M & !T & !P & !R) break;
        vector<vector<vector<int>>> teamScore(T, vector<vector<int>>(P, vector<int>(2)));
        int m, t, p, j;
        for (int i = 0; i < R; i++) {
            cin >> m >> t >> p >> j;
            if (j == 0) {
                teamScore[t - 1][p - 1][0] = M + m;
            } else {
                teamScore[t - 1][p - 1][1]++;
            }
        }
        vector<vector<int>> ranking(T, vector<int>(3, 0));
        for (int i = 0; i < teamScore.size(); i++) {
            int totalTime = 0;
            int solveCount = 0;
            for (int j = 0; j < teamScore[i].size(); j++) {
                if (teamScore[i][j][0] != 0) {
                    solveCount++;
                    totalTime += teamScore[i][j][0] + teamScore[i][j][1] * 20;
                }
            }
            ranking[i][0] = i + 1;
            ranking[i][1] = solveCount;
            ranking[i][2] = totalTime;
        }

        stable_sort(ranking.begin(), ranking.end(), [](auto& x, auto& y) { return x[0] > y[0]; });
        stable_sort(ranking.begin(), ranking.end(), [](auto& x, auto& y) { return x[2] < y[2]; });
        stable_sort(ranking.begin(), ranking.end(), [](auto& x, auto& y) { return x[1] > y[1]; });
        for (int i = 0; i < ranking.size() - 1; i++) {
            cout << ranking[i][0];
            if (ranking[i][1] == ranking[i + 1][1] && ranking[i][2] == ranking[i + 1][2]) {
                cout << "=";
            } else {
                cout << ",";
            }
        }
        cout << ranking[ranking.size() - 1][0] << endl;
    }
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int h, w;
char c[110][110];
string s[4] = {"6314", "2020", "1364", "5050"};
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
bool used[110][110];

void dfs(int x, int y){
    if(used[x][y]) return;
    used[x][y] = true;
    rep(i, 4){
        int nx = x+dx[i], ny = y+dy[i];
        if(0<=nx && nx<100 && 0<=ny && ny<100){
            if(c[x][y] == s[x%4][y%4] && c[nx][ny] == s[nx%4][ny%4]){
                dfs(nx, ny);
            }
        }
    }
}

int main(){
    scanf("%d%d", &h, &w);
    rep(i, 100)rep(j, 100) c[i][j] = '/';
    rep(i, h)rep(j, w) scanf(" %c", &c[i][j]);
    rep(i, 100)rep(j, 100) used[i][j] = false;
    dfs(0, 0);
    puts(used[h-1][w-1] ? "YES" : "NO");
}


Measured memory_bytes: 3808
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var abc = ReadIntArray();
            var a = abc[0];
            var b = abc[1];
            var c = abc[2];
            var ans = b - a == c - b ? "YES" : "NO";
            Console.WriteLine($"{ans}");
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	vector<int> v(5);
	rep(i, 5) cin >> v[i];

	int ans = 1000;
	sort(all(v));
	do {
		int cur = 0;
		rep(i, 5) {
			if (i != 4 && v[i] % 10) {
				cur += (v[i] + (10 - v[i] % 10));
			} else {
				cur += v[i];
			}
		}
		chmin(ans, cur);
	} while (next_permutation(all(v)));
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    int N,T;
    int i,j;
    int tmp;
    cin >> N >> T;
    vector<int> c(N),t(N);
    REP(i,N) cin >> c.at(i) >> t.at(i);
    tmp=c.at(0);
    REP(i,N){
        for(j=1;i+j<N;j++){
            if(t.at(i)>t.at(i+j)){
                tmp=t.at(i);
                t.at(i)=t.at(i+j);
                t.at(i+j)=tmp;
                tmp=c.at(i);
                c.at(i)=c.at(i+j);
                c.at(i+j)=tmp;
            }
        }
    } 

    int g=10000;
    for(i=0;i<N&&(t.at(i))<=T;i++){
        if(g>c.at(i))g=c.at(i);
    }
    if(g==10000){
        cout << "TLE" << endl;
        return 0;
    }
    cout << g << endl;
    return 0;
}

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

#define MOD 1000000007
#define SIZE_1 2000005
#define SIZE_2 1000000
#define INT_BITS 32
typedef long long int ll;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<ll> vi;

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

    if(n >= 1 and n <= 9)
    {
        cout << n;
    }
    else if(n >= 10 and n <= 99)
    {
        cout << "9";
    }
    else if(n >= 100 and n <= 999)
    {
        cout << 10 + n - 100;
    }
    else if(n >= 1000 and n <= 9999)
    {
        cout << 909;
    }
    else if(n >= 10000 and n <= 99999)
    {
        cout << 910 + n - 10000;
    }
    else
        cout << 90909;

    return 0;
}


Measured memory_bytes: 256
(defvar N (read))
(defvar M (read))

(defparameter trans (make-hash-table :test #'equal))
(defparameter ht1 (make-hash-table :test #'equal))
(defparameter ht2 (make-hash-table :test #'equal))

(loop for i from 1 repeat N do
      (setf (gethash i trans) (read)))

(loop for i from 1 to M with now = 1
      if #1=(gethash now ht2)
      return (princ (gethash (+ #1# (mod (- M i) (- i #1#))) ht1))
      do (setf (gethash now ht2) i
               now (gethash now trans)
               (gethash i ht1) now)
      finally (princ now))

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

using namespace std;

int main()
{
  int n;
  cin>>n;
  vector<int>v(200005);
  for(int i=0;i<n-1;i++){
    int a;
    cin>>a;
    ++v[a];
  }
  for(int i=1;i<=n;i++){
    cout<<v[i]<<endl;
  }
}


Measured memory_bytes: 4048
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

n =int(input())

# n行の複数列ある数値を二次元配列へ。x[n][2]
ab = [[int(i) for i in input().split()] for i in range(n)] 

#print(ab)

ab.sort(key = lambda x: -x[1]-x[0])
#print(ab)
answer = 0
for i in range(n):
    if i % 2 == 0:
        answer += ab[i][0]
    else:
        answer -= ab[i][1]
print(answer)



Measured memory_bytes: 35072
import java.io.*;
import java.util.*;
class Main{
  static int input_n[];
  // static int input_q[];
  static int n;
  public static void main(String args[])throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    n = Integer.parseInt(br.readLine());
    // ArrayList<Integer> input = new ArrayList<Integer>();

    input_n= new int[n];
    StringTokenizer token = new StringTokenizer(br.readLine());
    for(int i = 0; i<n; i++) {
      input_n[i] = Integer.parseInt(token.nextToken());
    }

    int q = Integer.parseInt(br.readLine());
    //input_q = new int[q];
    token = new StringTokenizer(br.readLine());
    for(int i = 0; i<q; i++) {
      // input_q[i] = Integer.parseInt(token.nextToken());
      if(true==solve(0, Integer.parseInt(token.nextToken()))) System.out.println("yes");
      else System.out.println("no");
    }
  }
  static boolean solve(int i, int m){
    boolean res;
    if(m == 0)return true;
    if(i>=n)return false;
    res = solve(i+1 , m) || solve(i+1, m-input_n[i]);
    return res;
  }
}


Measured memory_bytes: 24680
n,m,q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(q)]
ans = 0

def score(A):
  scr = 0
  for a,b,c,d in abcd:
    if A[b]-A[a] == c:
      scr += d
  return scr 

def dfs(A,LEN):
  if LEN == n:
    global ans
    tmp = score(A)
    ans = max(ans, tmp)
  else:
    for i in range(A[-1],m+1):
      dfs(A+[i],LEN+1)

dfs([1],0)
print(ans)

Measured memory_bytes: 70732
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  ll N,A[1001],P,od=0,ev=0,ncr[102][102];
  REP(i,101){
    ncr[i][i] = 1;
    ncr[i][0] = 1;
  }
  REP(i,101){
    for(int j=0;j<i;j++)
      ncr[i+1][j+1] = ncr[i][j+1]+ncr[i][j];
  }
  cin >> N >> P;
  REP(i,N)cin >> A[i];
  REP(i,N){
    if(A[i]%2){
      od++;
    }else
      ev++;
  }
  ll res=0;
  if(P == 0){
    for(int i=0;2*i<=od;i++)
      res += ncr[od][2*i];
    res *= 1LL << ev;
    cout << res << endl;
  }else{
    for(int i=0;2*i+1<=od;i++)
      res += ncr[od][2*i+1];
    res *= (1LL << ev);
    cout << res << endl;
  }
           
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 384
#include <stdio.h>

int student[31];

int main(void)
{
	int i, j, k;
	
	student[0]++;
	
	for (i = 0; i < 28; i++){
		scanf("%d", &j);
		student[j]++;
	}
	
	for (i = 1; i < 31; i++){
		student[i] == 0 ? printf("%d\n", i) : 0;
	}
	
	return (0);
}

Measured memory_bytes: 1804
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)

    ans = 0
    cnt = 1
    i = 0
    for n in range(N-1):
        ans += A[i]
        cnt += 1
        if cnt == 2:
            i += 1
            cnt = 0
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 108732
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //ifstream cin("input.in");
    //ofstream cout("output2.out");
    ios::sync_with_stdio(0);cin.tie(0);
    bool B[10209]={0};
    B[0]=1;
    long N,X;
    cin>>N;
    for(long i=0;i<N;i++){
        cin>>X;
        for(long i=10200;i>=0;--i)
            if(B[i])
                B[i+X]=1;
    }
    long M=0;
    for(long i=0;i<=10200;i++){
        //cout<<i<<" "<<B[i]<<"\n";
        if(B[i])
            if(i%10!=0)
                M=i;
    }
    cout<<M;
}   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  vector<int> A={1,5,13,29,61,125,253,509,1021,2045,4093,8189,16381,32765,65533,131069,262141,524285,1048573,2097149,4194301,8388605,16777213,33554429,67108861,134217725,268435453,536870909,1073741821,2147483645,4294967293,8589934589,17179869181,34359738365,68719476733,137438953469,274877906941,549755813885,1099511627773,2199023255549,4398046511101,8796093022205,17592186044413,35184372088829,70368744177661,140737488355325,281474976710653,562949953421309,1125899906842621,2251799813685245,4503599627370493};
  vector<int> B={1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215,33554431,67108863,134217727,268435455,536870911,1073741823,2147483647,4294967295,8589934591,17179869183,34359738367,68719476735,137438953471,274877906943,549755813887,1099511627775,2199023255551,4398046511103,8796093022207,17592186044415,35184372088831,70368744177663,140737488355327,281474976710655,562949953421311,1125899906842623,2251799813685247};
  int N,X;
  cin>>N>>X;
  int ans=0;
  for(int i=N;i>0;i--){
    if(X>=A[i-1]+2)
      ans++;
    ans+=X/(A[i-1]+1)*B[i-1];
    X=X%(A[i-1]+1)-1;
    if(X<=0)
      break;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_125
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            long[] array = ReadLongs();
            int minusCnt = 0;
            long sum = 0;
            for(int i = 0; i < n; i++)
            {
                if (array[i] < 0) minusCnt++;
                array[i] = Abs(array[i]);
                sum += array[i];
            }
            if (minusCnt % 2 == 0)
            {
                WriteLine(sum);
            }
            else
            {
                Array.Sort(array);
                WriteLine(sum - array[0] * 2);
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 29660
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <cstdio>

using namespace std;

int main(){
    int n, m, x, ans=2000000;
    cin >> n >> m >> x;
    vector<vector <int>> p(n);
    for(int i=0; i<n; i++){
        for(int j=0; j<m+1; j++){
            int ac;
            cin >> ac;
            p[i].push_back(ac);
        }
    }

    for(int i=0; i<(1<<n); i++){
        vector<bool> v(n, false);
        for(int j=0; j<n; j++){
            if(i & (1<<j)){
                v[j] = true;
            }
        }
        vector<int> xs(m+1, 0);
        bool ok = true;
        for(int j=0; j<n; j++){
            if(v[j]){
               for(int k=0; k<m+1; k++){
                  xs[k] += p[j][k];
               }
            }
        }
        for(int j=1; j<m+1; j++){
            if(xs[j] < x) ok = false;
        }
        if(ok) ans = min(ans, xs[0]);
    }

    if(ans == 2000000){
       cout << -1 << endl;
    }else{
       cout << ans << endl;
    }

    return 0;

}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;

int main(){
	int a,b,c,d,e,f;

	double max=-1;
	double ans1=0,ans2=0;
	cin>>a>>b>>c>>d>>e>>f;
	double den=e*1./(100+e);
	for(int i=0;i<=100;i++)
	for(int j=0;j<=100;j++)
	for(int k=100;k>=0;k--)
	for(int l=100;l>=0;l--)
	{
		if(i==0&&j==0) continue;
		if((c*k+d*l)*1./(a*100*i+b*100*j+c*k+d*l)<=den  &&  (a*100*i+b*100*j+c*k+d*l)<=f)
		{
			if((c*k+d*l)*1./(a*100*i+b*100*j)>=max)
			{
			max=(c*k+d*l)*1./(a*100*i+b*100*j);
			ans1=a*100*i+b*100*j+c*k+d*l;
			ans2=c*k+d*l;
			}
		}
		
	}
	cout<<ans1<<" "<<ans2<<endl;
	return 0;


    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 1000050

struct Point {
    ll x,y;
    Point(ll a=0,ll b=0) {
        x = a; y = b;
    }
};

struct LineContainer {
    vector<Point> line;
    LineContainer() {
        line.resize(4 * N + 5,Point(0,inf));
    }
    ll dot(Point a,Point b) {
        return ( a.x * b.x + a.y * b.y);
    }
    ll f(Point a,ll x) {
        return dot(a,Point(x,1));
    }
    void add(Point nw,ll l=0,ll r=N,ll pos=1) {
        ll m = (l+r)/2;
        bool lef = f(nw,l) < f(line[pos],l);
        bool mid = f(nw,m) < f(line[pos],m);
        if(mid) swap(nw,line[pos]);
        if(r-l == 1) return;
        if(lef != mid) add(nw,l,m,2*pos);
        else add(nw,m,r,2*pos+1);
    }
    ll query(ll x,ll l=0,ll r=N,ll pos=1) {
        ll m = (l+r)/2;
        if(r-l == 1) return f(line[pos],x);
        if(x<m) return min(f(line[pos],x),query(x,l,m,2*pos));
        return min(f(line[pos],x),query(x,m,r,2*pos+1));
    }
};

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

    int n;ll c;
    cin>>n>>c;
    ll a[n];
    ifr(i,0,n) cin>>a[i];
    LineContainer li;
    ll dp[n];
    dp[0] = 0;
    li.add({-2*a[0],a[0]*a[0]});
    ifr(i,1,n) {
        dp[i] = c + a[i]*a[i] + li.query(a[i]);
        li.add({-2*a[i],a[i]*a[i]+dp[i]});
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 65920
a,b = map(int, input().split())
s = input()
count = 0
ans = 'Yes'
for i in range(a+b+1):
  if i == a:
    if s[i] != '-':
      ans = 'No'
      break
  else:
    if s[i] == '-':
      ans = 'No'
      break
print(ans)
    

Measured memory_bytes: 9036
class Node():
    def __init__(self):
        self.parent = -1
        self.children = []

def cal_depth(node_id, d = 0):
    Tree[node_id].depth = d
    for child in Tree[node_id].children:
        cal_depth(child, d+1)
    
N = int(input())
Tree = [Node() for _ in range(N)]

#make_tree
for _ in range(N):
    #id, 子供の数k, c_0~c_k
    tree_info = list(map(int, input().split()))
    node_id = tree_info[0]
    k = tree_info[1]
    if k > 0:
        children = tree_info[2:]
        Tree[node_id].children = children
        Tree[node_id].type = "internal node"
    else:
        Tree[node_id].type = "leaf"
        
    for child in Tree[node_id].children:
        Tree[child].parent = node_id

#search_root
root_id =[i for i,t in enumerate(Tree) if t.parent == -1][0]
Tree[root_id].type = "root"
cal_depth(root_id)


#answer_output
for i, t in enumerate(Tree):
    print("node {}: parent = {}, depth = {}, {}, {}".format(i, t.parent, t.depth, t.type, t.children))


Measured memory_bytes: 39992
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

struct UnionFind {
    vector<int> p;
    UnionFind(int n) {
        p = vector<int>(n, -1);
    }
    int parent(int a) {
        if (p[a] < 0) return a;
        return p[a] = parent(p[a]);
    }
    int size(int a) {
        return -p[parent(a)];
    }
    bool same(int a, int b) {
        return parent(a) == parent(b);
    }
    bool unite(int a, int b) {
        if (same(a, b)) return false;
        a = parent(a);
        b = parent(b);
        if (size(a) < (size(b))) {
            swap(a, b);
        }
        p[a] += p[b];
        p[b] = a;
        return true;
    }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uni(n);
    vector<int> num1(n, 0);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        uni.unite(a, b);
        ++num1[a];
        ++num1[b];
    }
    vector<int> num2(n, 0);
    rep(i, k) {
        int c, d;
        cin >> c >> d;
        --c, --d;
        if (uni.same(c, d)) {
            ++num2[c];
            ++num2[d];
        }
    }
    rep(i, n) {
        if (i != 0) cout << " ";
        cout << uni.size(i) - 1 - num1[i] - num2[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4544
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <list>

using namespace std;



int main(void){
    int N,K,A;
    int d,ans;
    map<int,int> mp;

    cin>>N>>K;

    for(int i=0;i<K;i++){
        cin>>d;
        for(int j=0;j<d;j++){
            cin>>A;
            mp[A]++;
        }
    }

    ans=N-mp.size();

    cout<<ans<<endl;
    
    




    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

int main(){
  int n;cin>>n;
  vi a(n);
  rep(i,n) cin>>a.at(i);
  string ans = "APPROVED";
  rep(i,n){
    if(a.at(i)%2==0){
      if(a.at(i)%3!=0 && a.at(i)%5!=0){
        ans="DENIED";
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void){

int  a , b , k , i , s = 0;
int  w[100];

scanf("%d %d %d",&a,&b,&k);
int m   = (a<b?a:b);

for(i = 1;i <=m;i++){
   if(a%i == 0&&b%i == 0){ 
     w[s] = i;
      s++;
}}

printf("%d",w[s-k]);

return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    int r = 0;
    int t = 1 << 30;
    for (int i = 0; i < n; i++) {
        int s;
        cin >> s;
        r += s;
        if (s % 10 != 0 && s < t) {
            t = s;
        }
    }

    if (r % 10 == 0) {
        if (t == 1 << 30) {
            r = 0;
        } else {
            r -= t;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int a,b,c,x;
    scanf("%d %d %d %d",&a,&b,&c,&x);
    int count = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if(500 * i + 100 * j + 50 * k == x){
                    count++;
                }
            }
        }
    }
    printf("%d\n",count);
    
    return 0;
}

Measured memory_bytes: 128
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
v = list(li())
c = list(li())

ans = 0
for vi, ci in zip(v, c):
    if vi-ci > 0:
        ans += (vi-ci)
        
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    try {
      int n = scanner.nextInt();
      String s = scanner.next();
      int k = scanner.nextInt();
      char a = s.charAt(k-1);

      String ans = "";
      for (int i = 0; i < n; i++) {
        if (s.charAt(i) == a) {
          ans += s.charAt(i);
        } else {
          ans += "*";
        }
      }
      System.out.println(ans);
    } finally {
      scanner.close();
    }
  }
}


Measured memory_bytes: 39572
#include <stdio.h>
int main(void)
{
	int A, B, C, K,max=0,min=0,a=0;
	scanf("%d%d%d", &A, &B, &C);
	scanf("%d", &K);
	max = A;
	if (max < B) {
		min = max;
		max = B;
	}
	else min = B;
	if (max < C)
	{
		min += max;
		max = C;
	}
	else min += C;
     a = max;
	for (int i = 1; i <= K; i++) {
		a = a * 2;
	}
	
	printf("%d\n", a+min);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const long long mod = 1e9 + 7;

long long a, b, v, w, t;
void solve(){
    if(a < b){
        a += v * t;
        b += w * t;
        if(a >= b)
            cout << "YES";
        else
            cout << "NO";
    }
    else{
        a -= v * t;
        b -= w * t;
        if(a <= b)
            cout << "YES";
        else
            cout << "NO";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> v >> b >> w >> t;
    int i = 0;
    solve();
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<long long,long long>
#define ppii pair<long long,pair<long long,long long>>
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define mod 1000000007
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define pyes cout << "Yes" << endl
#define pno cout << "No" << endl
typedef vector<vector<long long>> vii;
typedef unsigned long long lint;
typedef unsigned long long ll;
lint qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
lint gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e14;
const int MAX_N = 1 << 17;
const int cf = 100010;
///////////////////////////////////////////////////////////////////////////////

int main() {
	lint a, b, c, d; cin >> a >> b >> c >> d;
	lint k = c * d / gcd(c, d);
	lint lyn = b / c + b / d - b / k - (a / c + a / d - a / k);
	lint rn = b - a + 1;
	int g = 0;
	if (!(a % c == 0 || a % d == 0)) g = 1;
	cout << (b - (b / c + b / d - b / k)) - (a - (a / c + a / d - a / k)) + g<< endl;
	return 0;

}

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

typedef long long ll;
typedef unsigned long long ull;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

ll A, B, C;
ll K;

int main(){

    cin >> A >> B >> C >> K;
    if(K % 2 == 1){
        ll a = -A + B;
        cout << a << endl;
    }
    else{
        ll a = A - B;
        cout << a << endl;
    }

    return 0;
}


Measured memory_bytes: 256
// A - AtCoder Crackers
// https://beta.atcoder.jp/contests/abc105/tasks/abc105_a

import scala.io.StdIn.readLine

object Main extends App {

  val Array(n, k) = readLine.split(" ").map(_.toInt)

  val diff = if (n%k == 0) 0 else 1

  println(diff)

}

Measured memory_bytes: 27444
n,m=map(int,input().split())
l_list,r_list=[],[]
for _ in range(m):
  l,r=map(int,input().split())
  l_list.append(l)
  r_list.append(r)
ans=max(0,min(r_list)-max(l_list)+1)
print(ans)

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

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef complex<double> com;

#define MOD 1000000007
#define PI 3.14159265359
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;

void test()
{
	int n,c=0,ans=0;
	cin>>n;

	string s;
	cin>>s;

	for(int i=0;i<n;i++)
	{
		if(s[i]=='W')
			c++;
	}

	reverse(s.begin(),s.end());

	for(int i=0;i<c;i++)
	{
		if(s[i]=='R')
			ans++;
	}

	cout<<ans<<endl;
}

int main()
{   
fast_io();
cout << fixed << setprecision(15);
int t = 1;

//cin>>t;

for(int i = 0; i < t; i++)
{
	test();
}
return 0;
}

Measured memory_bytes: 3768
#include <cstdio>
#include <cstdlib>

int main()
{
        int x, a, b;
        scanf("%d%d%d", &x, &a, &b);

        int dstA = abs(x - a), dstB = abs(x - b);
        char ans = dstA < dstB ? 'A' : 'B';
        printf("%c\n", ans);
}


Measured memory_bytes: 128
#include<stdio.h>
int main()
{   
    char a[4];
    int x,y,z,p;
	scanf("%s",&a);
	x=a[0]-'0';
	y=a[1]-'0';
	z=a[2]-'0';
	p=a[3]-'0';
	if(x+y+z+p==7)
	{
		printf("%d+%d+%d+%d=7\n",x,y,z,p);
		return 0;
	}
	if(x+y+z-p==7)
	{
		printf("%d+%d+%d-%d=7\n",x,y,z,p);
		return 0;
	}
	if(x+y-z+p==7)
	{
		printf("%d+%d-%d+%d=7\n",x,y,z,p);
		return 0;
	}
	if(x-y+z+p==7)
	{
		printf("%d-%d+%d+%d=7\n",x,y,z,p);
		return 0;
	}
	if(x+y-z-p==7)
	{
		printf("%d+%d-%d-%d=7\n",x,y,z,p);
		return 0;
	}
	if(x-y+z-p==7)
	{
		printf("%d-%d+%d-%d=7\n",x,y,z,p);
		return 0;
	}
	if(x-y-z+p==7)
	{
		printf("%d-%d-%d+%d=7\n",x,y,z,p);
		return 0;
	}
	if(x-y-z-p==7)
	{
		printf("%d-%d-%d-%d=7\n",x,y,z,p); 
		return 0;
	}	
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 998244353;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;

const int MAX = 2000010;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	COMinit();
	int N, M, K;
	cin >> N >> M >> K;
	int sum = 0;
	int ans[N+1]{};
	int ans1[N+1]{};
	for(int i=N-1;i>=0;i--){
		if(i == N-1){
			ans[i] = M;
		}
		else{
			ans[i] = ans[i+1] * (M-1);
			ans[i] %= MOD;
		}
		ans1[i] = ans[i] * COM(N-1, i);
		ans1[i] %= MOD;
	}
	
	rep(i,K+1){
		sum += ans1[i];
		sum %= MOD;
	}
	cout << sum << endl;
}

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

using namespace std;

#define DIM 200009
#define INF ((long long)1e18+9ll)
#define pairll pair<long long,long long>
#define fi first
#define se second
#define ld long double
#define amen exit(0)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define endl '\n'
#define y1 trymax_lox
#define y2 sijgkvdfbo
#define eps 1000000

long long i,j,k,l,n,m;

long long dp[DIM];

pairll a[DIM];

inline bool cmp(pairll a,pairll b){
    if(a.se!=b.se)return a.se<b.se;
    return a.fi<b.fi;
}

long long f[DIM];

void add(long long x,long long d){
    for(int i=x;i<DIM;i+=i&-i)f[i]=max(f[i],d);
}

long long get(long long x){
    long long res=0;

    for(int i=x;i>0;i-=i&-i)res=max(res,f[i]);

    return res;
}

vector<long long>nums;

long long pos(long long x){
    return lower_bound(nums.begin(),nums.end(),x)-nums.begin();
}

int main(){

    //freopen("threesum.in","r",stdin);
    //freopen("threesum.out","w",stdout);

    fast;

    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i].fi>>a[i].se;
        a[i]={a[i].fi-a[i].se,a[i].fi+a[i].se};
        nums.push_back(a[i].se);
    }

    sort(a+1,a+1+n,cmp);
    sort(nums.begin(),nums.end());

    for(i=1;i<=n;i++){
        k=pos(a[i].fi+1);
        dp[i]=get(k)+1;
        add(i,dp[i]);

        l=max(l,dp[i]);

       // cout<<a[i].fi<<' '<<a[i].se<<' '<<dp[i]<<endl;
    }

    cout<<l<<endl;

    amen;
}

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

int main() {
  long n,q;
  cin >> n >> q;
  vector<long> s(n);
  vector<long> t(n);
  vector<long> x(n);
  vector<long> d(q);
  vector<vector<long>> aaa;
  map<long,long> bbb;
  for(long i=0;i<n;i++) cin >> s[i] >> t[i] >> x[i];
  for(long i=0;i<q;i++) cin >> d[i];

  for(long i=0;i<n;i++) {
    aaa.push_back({s[i]-x[i],0,x[i]});
    aaa.push_back({t[i]-x[i]-1,2,x[i]});
  }
  for(long i=0;i<q;i++) aaa.push_back({d[i],1});
  
  sort(aaa.begin(),aaa.end());
  for(long i=0;i<aaa.size();i++) {
    if(aaa[i][1]==0) {
      bbb[aaa[i][2]]++;
    } else if(aaa[i][1]==1) {
      if(bbb.size()==0) cout << -1 << endl;
      else cout << (*bbb.begin()).first << endl;
    } else {
      bbb[aaa[i][2]]--;
      if((*bbb.find(aaa[i][2])).second==0)  bbb.erase(bbb.find(aaa[i][2]));
    }
  }
}

Measured memory_bytes: 53028
#include<bits/stdc++.h>
using namespace std;
int n, m, ara[81][81], b[81][81];
int mem[81][81][6401];
int dp(int x, int y, int s)
{
    if(x>n || y>m || s>6400)return 80;
    if(x==n && y==m)return min(s+abs(ara[x][y]-b[x][y]), abs(s-abs(ara[x][y]-b[x][y])));
    if(mem[x][y][s]!=-1)return mem[x][y][s];
    mem[x][y][s]= dp(x+1, y, s+abs(ara[x][y]-b[x][y]));
    mem[x][y][s]= min(dp(x, y+1, s+abs(ara[x][y]-b[x][y])), mem[x][y][s]);
    mem[x][y][s]= min(dp(x+1, y, abs(s-abs(ara[x][y]-b[x][y]))), mem[x][y][s]);
    mem[x][y][s]= min(dp(x, y+1, abs(s-abs(ara[x][y]-b[x][y]))), mem[x][y][s]);
    return mem[x][y][s];
}
int main()
{
//    cerr<<(sizeof mem)/(1024*1024)<<endl;
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++)
    for(int j=1; j<=m; j++)
    scanf("%d", &ara[i][j]);
    for(int i=1; i<=n; i++)
    for(int j=1; j<=m; j++)
    scanf("%d", &b[i][j]);
    memset(mem, -1, sizeof mem);
    printf("%d\n", dp(1, 1, 0));
    return 0;
}


Measured memory_bytes: 164352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(j, m) for (int j = 0; j < (int)(m); j++)
#define rep2(i, l, n) for (int i = l; i < (int)(n); i++)


int main() {
    string S;
    cin >> S;
    cout << S[0] << S.size() - 2 << S[S.size() - 1] << endl;
}



Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if (x % 100 <= x / 100 * 5) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }

}

Measured memory_bytes: 23124
import math

K = int(input())

sum = 0
            
for a in range(1, K+1, 1):
    for b in range(1, K+1, 1):
        tmp = math.gcd(a,b)
        for c in range(1, K+1, 1):
            sum = sum + math.gcd(tmp, c)
print(sum)

Measured memory_bytes: 9128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  vector<ll> num(n);
  ll all = 0;
  for(int i = 0;i <= n - 1;i++){
    cin >> num[i];
    all += num[i];
  }
  ll res = 0;
  res = INT_MAX;
  ll now = 0;
  for(int i = 0;i <= n - 2;i++){
    now += num[i];
    res = min(res,max(all - now,now) - min(all - now,now));
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1792
S = input()
T = input()
alphabets = "abcdefghijklmnopqrstuvwxyz"

S_list=[]
T_list=[]
for c in alphabets:
    Scnt = S.count(c)
    Tcnt = T.count(c)
    if Scnt > 0:
        S_list.append(Scnt)
    if Tcnt > 0:
        T_list.append(Tcnt)

if sorted(S_list) == sorted(T_list):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int pattern = 1;
    for (int i = 0; i < N; ++i) {
        if (i == 0) pattern *= K;
        else pattern *= (K - 1);
    }

    cout << pattern << endl;

    return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<string> vvs;

const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    int h, w;

    cin >> h >> w;
    char board[100][100];
    bool visited[100][100];

    REP(i, h) {
        REP(j, w) {
            cin >> board[i][j];
            visited[i][j] = false;
        }
    }

    int ans = 0;
    queue<tuple<int, int, int>> q;

    REP(i, h) {
        REP(j, w) {
            int dist = 0;
            if (board[i][j] == '#') continue;
            q.push(make_tuple(i, j, 0));
            visited[i][j] = true;

            while (!q.empty()) {
                tuple<int, int, int> front = q.front();
                q.pop();
                int x = get<0>(front);
                int y = get<1>(front);
                int d = get<2>(front);

                for (int dx = -1; dx <= 1; ++dx) {
                    for (int dy = -1; dy <= 1; ++dy) {
                        if (!((dx == -1 && dy == 0) ||
                              (dx == 1 && dy == 0) ||
                              (dx == 0 && dy == -1) ||
                              (dx == 0 && dy == 1)))
                            continue;

                        int nx = x + dx;
                        int ny = y + dy;
                        if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
                        if (board[nx][ny] == '#') continue;
                        if (visited[nx][ny]) continue;

                        visited[nx][ny] = true;
                        q.push(make_tuple(nx, ny, d + 1));
                        dist = d+1;
                    }
                }
            }

            ans = max(ans, dist);
            REP(k, h) {
                REP(l, w) {
                    visited[k][l] = false;
                }
            }
        }
    }

    MSG(ans)
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    ls = [0] * n

    for i in range(n-1, -1, -1):
        if (sum(ls[i::i+1]) % 2) != a[i]:
            ls[i] = 1
    sum_ls = sum(ls)
    print(sum_ls)
    if sum_ls:
        print(*[i+1 for i, v in enumerate(ls) if v == 1])

if __name__ == '__main__':
    main()


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

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    int A = abs(x - a);
    int B = abs(x - b);
    if (A < B) {
        cout << "A" << endl;
    } else {
        cout << "B" << endl;
    }
    return 0;
}

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

#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int h,w;cin>>h>>w;
  vector<string> s(h);
  for (int i=0; i<h; i++) {
    cin>>s[i];
  }

  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (s[i][j]=='#') {
        if (s[max(0,i-1)][j] == '.'
            && s[min(h-1, i+1)][j] == '.'
            && s[i][max(0, j-1)] == '.'
            && s[i][min(w-1, j+1)] == '.') {
          cout << "No" << endl;
          return;
        }
      }
    }
  }

  cout << "Yes" << endl;
}

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


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

int main() {
  string S;
  cin >> S;
  int ans = 0;
  if (S.at(0)=='1') {
    ans++;
  };
  if (S.at(1)=='1') {
    ans++;
  };
  if (S.at(2)=='1') {
    ans++;
  };
  cout << ans << endl;
}

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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

int main(){

  string s;
  cin >> s;

  //int len = s.size();

  //vector<vector<int>> dp;

  int cnt = 0;
  int ans = 0;
  rep(i, s.size()){
    if(s[i] == 'g'){
      if(cnt > 0){
        cnt--;
        ans++;
      }
      else cnt++;
    }
    else{
      if(cnt > 0) cnt--;
      else{
        cnt++;
        ans--;
      }
    }
  }

  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

bool g[10][10];
bool v[10];
int n, m;
int a, b;

int dfs(int now);

int main()
{

    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;

        --a; --b;
        
        g[a][b] = true;
        g[b][a] = true;
    }

    v[0] = true;
    cout << dfs(0) << endl;
    
    return 0;
}

int dfs(int now)
{
    bool f = true;

    for (int i = 0; i < n; i++) {
        f = f & v[i];
    }

    if (f) {
        return 1;
    }

    int rec = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] == false && g[now][i]) {
            v[i] = true;
            rec += dfs(i);

            v[i] = false;
        }
    }

    return rec;
}


Measured memory_bytes: 256