akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<queue>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;

#define  N 11000

struct Edge
{
    int u,v;
    double d;
}edge[N*N/2+10];

struct node
{
    double x,y;
}p[N];

int n,m;
int father[N];

int cmp(struct Edge h,struct Edge f)
{
    return h.d>f.d;
}

double Dist(node a,node b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

int Find(int x)
{
    while(x!=father[x])
        x=father[x];
    return x;
}

int main()
{
    int i,a,b;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(i=1;i<=n;i++)
            father[i]=i;

        for(i=1;i<=n;i++)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
        }

        double sum=0.0;   ///sum是巫婆?得??和
        for(i=0;i<m;i++)
        {
            scanf("%d%d",&a,&b);
            edge[i].u=a;
            edge[i].v=b;
            edge[i].d=Dist(p[a],p[b]);
            sum=sum+edge[i].d;
        }

        sort(edge,edge+m,cmp);

        double s=0.0;   ///??不用抹去的?，?似Kruskal求最小生成?
        for(i=0;i<m;i++)
        {
            int x,y;
            x=Find(edge[i].u);
            y=Find(edge[i].v);
            if(x!=y)
            {
                if(x>y)
                    father[x]=y;
                else
                    father[y]=x;

                s=s+edge[i].d;
            }
            else
                continue;
        }
        double ans=0.0;
        ans=sum-s;  
        printf("%.3f\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1908
#include <stdio.h>
#include <string.h>
#include <ctype.h>


//void???????????¨???1???????????\??????????????¨????????????????????????????????????????????????
int main(void){
	char p[1000];
	char s[10];
	int count=0;
	int i;

	
	scanf("%s", s);
	for(i=0; i<strlen(s); i++){
		s[i] = tolower(s[i]);
	}

	while(1){
		scanf("%s", p);
		if(strcmp(p,"END_OF_TEXT")==0)
			break;	
		for(i=0; i<strlen(p); i++){
			p[i] = tolower(p[i]);
		}
		if(strcmp(p,s)==0)
			count++;
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 552
#include <iostream>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    if(0 < a){
        cout << "Positive" << endl;
    }
    else if(a == 0 or b == 0) {
        cout << "Zero" << endl;
    }
    else if(a < 0 and 0 < b){
        cout << "Zero" << endl;
    }
    else if((b - a) % 2 == 1){
        cout << "Positive" << endl;
    }
    else{
        cout << "Negative" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		String oBefore = scanner.nextLine();
		String oBehind = scanner.nextLine();

		
		char[] before = oBefore.toCharArray();
		char[] behind = oBehind.toCharArray();
		
		Arrays.sort(before);
		Arrays.sort(behind);
		
		char[] reverse = new char[behind.length];
		for (int i = 0; i < reverse.length; i++) {
			reverse[reverse.length-i-1] = behind[i];			
		}
		
		String ans = "Yes";
		if (String.valueOf(before).compareToIgnoreCase(String.valueOf(reverse))>=0 ) {
			ans="No";
		}
		
		System.out.println(ans);
		scanner.close();
	}

}

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

int main() {
	int a, b;
	cin >> a >> b;
	cout << a - 1 + (a <= b ? 1 : 0);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まずa-1月までは当然高橋が1個ずつあり、最後にa月に高橋があったかのみ調べれば良い
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a,b;
	cin>>n>>a>>b;
	long long x=a+b;
	long long A=n%x,B=n/x;
	if(A==0)
	{
		cout<<B*a;
		return 0;
	}
	else if(A>=a)
	{
		cout<<B*a+a;
		return 0;
	}
	else if (A<a)
	{
		cout<<B*a+A;
		return 0;
	}
 } 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int N, K;
	int D[20], count[10] = { 0 };
	cin >> N >> K;
	for (int i = 0; i < K; i++) {
		cin >> D[i];
		count[D[i]]++;
	}
	int pay = N;
	while (true) {
		int tmp = pay;
		while (tmp > 0) {
			if (count[tmp % 10] != 0) {
				pay++;
				break;
			}
			tmp /= 10;
		}
		if (tmp == 0) {
			cout << pay << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
N = int(input())
tmp = input().split()
H = []
for i in range(len(tmp)):
  H.append(int(tmp[i]))

ans = 0
for i in range(len(H)):
  chkflg = True
  if i >= 1:
    for j in range(i): 
      if H[j] > H[i]:
        chkflg = False
        break

  if chkflg: ans += 1

print(ans)   



Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		int[] a = new int[n];

		for(int i = 0;i < n; i++) {
			a[i] = s.charAt(i) - '0';
		}

		char[] c = new char[n-1];

		for ( int bit = 0; bit < (1 << n); bit ++){

			int sum = a[0];

			for ( int j = 0; j < n-1; j++){

				if ( (bit >> j & 1) == 1){
					sum += a[j+1];
					c[j] = '+';

				} else {
					sum -= a[j+1];
					c[j] = '-';
				}

			}

			if (sum == 7){
				for ( int k = 0; k < n; k++){
					if ( k == n -1){
						System.out.print(a[k]);
					} else {
						System.out.print(a[k]);
						System.out.print(c[k]);
					}
				}
				System.out.println("=7");
				break;
			}

		}


	}

}


Measured memory_bytes: 23892
import collections 
n,m = map(int,input().split())
g = collections.defaultdict(list)
for i in range(m):
  a,b= map(int,input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
  
#print(g)

ans = 0
def dfs(node,num,visit):
  visite = visit.copy()
  global ans
  num += 1
  if num == n:
    ans += 1
    return
  else:
    visite[node] = True
    for neib in g[node]:
      if visite[neib] == False:
        dfs(neib,num,visite)
  
visited = [False]*n
dfs(0,0,visited)
print(ans)


Measured memory_bytes: 74380
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( '\n' );
  console.log( data[1].split( ' ' ).reverse().join( ' ' ) );
});

Measured memory_bytes: 7644
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>
#include<numeric>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define what_is(x) cout<<#x<<" is "<<x<<en;

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

void solve()
{
	ll n, m;
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2;

}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type point struct {
	x, y, h int
}

func solve() {
	n := getInt()
	ps := make([]point, n)
	not0Height := -1
	for i := range ps {
		x, y, h := getInt(), getInt(), getInt()
		ps[i] = point{x, y, h}
		if h != 0 && not0Height == -1 {
			not0Height = i
		}
	}

	var center point
finLoop:
	for cx := 0; cx <= 100; cx++ {
	nextLoop:
		for cy := 0; cy <= 100; cy++ {
			ch := ps[not0Height].h + abs(ps[not0Height].x-cx) + abs(ps[not0Height].y-cy)
			for _, p := range ps {
				switch p.h {
				case 0:
					dist := abs(p.x-cx) + abs(p.y-cy)
					if dist < ch {
						continue nextLoop
					}
				default:
					nowCh := p.h + abs(p.x-cx) + abs(p.y-cy)
					if ch != nowCh {
						continue nextLoop
					}
				}
			}
			center = point{cx, cy, ch}
			break finLoop
		}
	}

	fmt.Fprintln(wr, center.x, center.y, center.h)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  ll ans=0;
  for(ll i=1;i<=N;i+=2) {
    ll count=0;
    for(ll j=1;j<=i;j++) {
      if(i%j==0) {
count++;
      }
    }
    
    if(count==8) {
      ans++;
    }
  }
  
  cout<<ans<<endl;
}




  

Measured memory_bytes: 3620
#include <stdio.h>
int main(void) {
  int n, count;
  
  scanf("%d",&n);
  while(n != 0) {
    count = 0;
    while(n != 1) {
      if(n % 2) {
	n = n * 3 + 1;
      } else {
	n /= 2;
      }
      count++;
    }
    printf("%d\n",count);
    scanf("%d",&n);
  }
  return(0);
}

Measured memory_bytes: 600
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define rep0(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
ll longinf=1ll<<60;
int inf=1<<29;
ll mod=1000000000+7;

ll mul(ll a,ll b){
    return (a%mod)*(b%mod)%mod; 
}
ll sum(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll pow(ll n){
    if(n==0) return 1;
    else if(n%2==0) return (pow(n/2)%mod)*(pow(n/2)%mod)%mod;
    else return ((pow(n-1)%mod)*3)%mod;
}

string s;
int a[100001];
int b[100001];
int c[100001];
int q[100001];
ll ans;
 
int main(){
    cin>>s;
    int n=s.size();
    rep0(i,n){
        if(i!=0){
            a[i]=a[i-1];
            b[i]=b[i-1];
            c[i]=c[i-1];
            q[i]=q[i-1];
        }
        if(s[i]=='A'){
            a[i]++;
        }
        if(s[i]=='B'){
            b[i]++;
        }
        if(s[i]=='C'){
            c[i]++;
        }
        if(s[i]=='?'){
            q[i]++;
        }
    }
    int Q=q[n-1];
    rep0(i,n){
        if(s[i]=='B'){
            ans=sum(ans,mul(a[i]*pow(Q),c[n-1]-c[i]));
            if(Q>=1){
                ans=sum(ans,mul(q[i]*pow(Q-1),(c[n-1]-c[i])));
                ans=sum(ans,mul(a[i]*pow(Q-1),(q[n-1]-q[i]))); 
            }
            if(Q>=2){
                ans=sum(ans,mul(q[i]*pow(Q-2),(q[n-1]-q[i])));
            }
        }
        if(s[i]=='?'){
                ans=sum(ans,mul(a[i]*pow(Q-1),(c[n-1]-c[i])));
            if(Q>=2){
                ans=sum(ans,mul((q[i]-1)*pow(Q-2),(c[n-1]-c[i])));
                ans=sum(ans,mul(a[i]*pow(Q-2),(q[n-1]-q[i]))); 
            }
            if(Q>=3){
                ans=sum(ans,mul((q[i]-1)*pow(Q-3),(q[n-1]-q[i])));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

bool po(int y,int m,int d){
  if(y<2019)return true;
  if(y>2019)return false;
  if(m<4)return true;
  if(m>4)return false;
  if(d<=30)return true;
  return false;
}

int main(){
  int y,m,d;
  scanf("%d/%d/%d",&y,&m,&d);
  puts(po(y,m,d) ? "Heisei" : "TBD");
  return 0;
}


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

int main(){
  string s; cin >> s;
  int n; n = s.size();
  int f = 0;
  int x = 0;
  int c;
  for (int i=0;i<n;i++){
    c = s[i] - '0';
    f += c;
    x += c*pow(10,n-i-1);
  }
  if (x%f == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    public static void Main()
    {
        int input = int.Parse(Console.ReadLine());
        long ans = 0;
        for(int i = 1; i <= input; i++)
        {
            for(int j = 1; j <= input; j++)
            {
                int temp = Gcd(i, j);
                for(int k = 1; k <= input; k++)
                {
                    ans += Gcd(temp, k);
                }
            }
        }
        Console.WriteLine(ans);
    }
    public static int Gcd(int a, int b)
    {
        return a > b ? GcdRecursive(a, b) : GcdRecursive(b, a);
    }

    private static int GcdRecursive(int a, int b)
    {
        return b == 0 ? a : GcdRecursive(b, a % b);
    }
}

Measured memory_bytes: 27528
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();

        List<Integer> candidates = new ArrayList<>();
        for (int i = 1; i <= 100; i++) {
            if (((A % i) == 0) && ((B % i) == 0)) {
                candidates.add(i);
            }
        }
        candidates.sort((a, b) -> b - a);

        System.out.println(candidates.get(K - 1));
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }

}


Measured memory_bytes: 28244
from collections import deque
n,m = [int(i) for i in input().split()]
F = [{} for i in range(n)]
for _ in range(m):
    i,j = [int(i) for i in input().split()]
    F[i][j] = 1
    F[j][i] = 1
q = int(input())
DP = [0 for i in range(n)]
c = 1
d = deque()
for i in range(n):
    if not DP[i]:
        d.append(i)
    while(len(d)>0):
        tmp = d.pop()
        DP[tmp] = c
        for i in F[tmp]:
            if not DP[i]:
                d.append(i)
    c+=1

for i in range(q):
    s,t = [int(i) for i in input().split()]
    if DP[s] == DP[t]:
        print("yes")
    else:
        print("no")


Measured memory_bytes: 38744
//  // https://atcoder.jp/contests/abc104/tasks/abc104_c

#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;


int D, G;
const int MAX_D = 10;
int p[MAX_D + 1], c[MAX_D + 1];

void solve() {
  int ans = 1000;
  for (int bit = 0; bit < (1 << D); bit++) {
    int sum = 0;
    int count = 0;
    for (int i = 0; i < D; i++) {
      if (bit & (1 << i)) {
        sum += (i + 1) * 100 * p[i] + c[i];
        count += p[i];
      }
    }

    if (sum >= G) ans = min(ans, count);
    else {
      for (int i = D - 1; i >= 0; i--) {
        if (bit & (1 << i)) continue;
        for (int j = 0; j < p[i]; j++) {
          if (sum >= G) break;
          sum += 100 * (i + 1);
          count++;
        }
      }
    }
    ans = min(ans, count);
  }
  printf("%d\n", ans);
}

int main() {
  scanf("%d %d", &D, &G);
  for (int i = 0; i < D; i++) {
    scanf("%d %d", &p[i], &c[i]);
  }
  solve();
}


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

using namespace std;

int main() {
	string w;
	int alf[32] = {0};

	cin >> w;
	for(int i = 0; i < w.size(); i++) {
		alf[w[i] - 'a']++;
	}
	
	
	int oddsum = 0;
	for(int i = 0; i < 25; i++) {
		oddsum += alf[i] % 2;
	}

	if(oddsum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}



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

const int mod = 998244353;
ll dp[5999][3000];

int a, b, c, d;
int main() {
	cin >> a >> b >> c >> d;
	dp[0][0] = 1;
	for (int k = 1; k <= c - a + d - b; ++k)
		for (int i = 0; i <= min(k, c - a); ++i) {
			int j = k - i;
			if (i > 0)
				dp[k][i] += dp[k - 1][i - 1] * (b + j);
			if (j > 0)
				dp[k][i] += dp[k - 1][i] * (a + i);
			if (i * j > 0)
				dp[k][i] -= dp[k - 2][i - 1] * (a + i - 1) * (b + j - 1);

			dp[k][i] %= mod;
		}
	if (dp[c - a + d - b][c - a] < 0)
		dp[c - a + d - b][c - a] += mod;
	cout << dp[c - a + d - b][c - a] << endl;
}


Measured memory_bytes: 119736
S=list(input())
T=list(input())
N=len(S)
D1={}
D2={}
count=0
for i in range(N):
    s=S[i]
    t=T[i]
    if s not in D1:
        D1[s]=count
        S[i]=count
    else:
        S[i]=D1[s]
    if t not in D2:
        D2[t]=count
        T[i]=count
        count+=1
    else:
        T[i]=D2[t]

for i in range(N):
    s=S[i]
    t=T[i]
    if s!=t:
        print("No")
        exit()
print("Yes")


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

using namespace std;

int main()
{
    string s;
    int c = 0;
    bool v1 = false,v2 = true,v3 = false;
    cin >> s;
    for (int i = 0; i < s.length();++i){
        if(i >= 2 && i <= s.length()- 2 && s[i] == 'C' && isupper(s[i])){
            v1 = true;
            c++;
            if(c > 1){v1 = false;}
        }
        if(isupper(s[i]) && s[i] != 'C' && s[i] != 'A'){v2 = false;}
        if(s[0] == 'A'){v3 = true;}
    }
    if(v1 && v2 && v3){cout << "AC";}else{cout << "WA";}
    return 0;
}


Measured memory_bytes: 256
fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {a} else {gcd(b, a % b)}
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let a: u64 = it.next().unwrap().parse().unwrap();
    let b: u64 = it.next().unwrap().parse().unwrap();
    let mut g = gcd(a, b);
    let mut ans = 1;
    let mut k = 2;
    while k * k <= g {
        if g % k == 0 {
            ans += 1;
            while g % k == 0 {
                g /= k;
            }
        }
        k += 1;
    }
    if g > 1 {
        ans += 1;
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    long long n; std::cin >> n;
    std::vector<int> a(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    int ans = 1e9;
    for (int i = -100; i <= 100; i++) {
        int s = 0;
        for (int j = 0; j < n; j++) {
            s += std::abs(i - a[j])*std::abs(i - a[j]);
        }
        ans = std::min(ans, s);
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[]
if n==1:
    print(a[0])
else:
    for i in range(n-k+1):
        if a[i]<=0 and 0<=a[i+k-1]:
            s.append(min(2*a[i+k-1]-a[i],a[i+k-1]-2*a[i]))
        elif a[i+k-1]<=0:
            s.append(-a[i])
        else:
            s.append(a[i+k-1])
    print(min(s))

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

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

//XY p1 = {0,0}, p2 = {100,0};
//XY s,t,u;

void kock(int,XY,XY);

int main() {
  int n;
   XY p1 = {0,0}, p2 = {100,0};
  
  scanf("%d",&n);
  
  printf("%.8f %.8f\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);
    
  return 0;
}

void kock(int n,XY p1,XY p2)
{
  XY s,t,u;
  if(n == 0) return;

  s.x = (2*p1.x + 1*p2.x)/3;
  s.y = (2*p1.y + 1*p2.y)/3;
  t.x = (1*p1.x + 2*p2.x)/3;
  t.y = (1*p1.y + 2*p2.y)/3;
  u.x = (t.x - s.x)*cos(M_PI/3) - (t.y - s.y)*sin(M_PI/3) + s.x;
  u.y = (t.x - s.x)*sin(M_PI/3) + (t.y - s.y)*cos(M_PI/3) + s.y;
  
  kock(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  kock(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  kock(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  kock(n-1,t,p2);
}



Measured memory_bytes: 2104
A,B = map(int,input().split())

a1 = A + B
a2 = A - B
a3 = A * B

if a1 >= a2 and a1 >= a3:
	print(a1)
elif a2 >= a1 and a2>= a3:
	print(a2)
elif a3 >= a1 and a3 >= a2:
	print(a3)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <random>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }

int main(){
	ll d ; cin >> d ;
	vll c(26) ;
	for(auto &i:c) cin >> i ;
	vvll di(d,vll(26)) ;
	for(int i=0;i<d;i++) for(int j=0;j<26;j++) cin >> di.at(i).at(j) ;
	vll last(26,-1) ;
	random_device rd ;
	for(int i=0;i<d;i++) cout << rd()%26+1 << endl ;
}




Measured memory_bytes: 3728
# -*- coding: utf-8 -*-
import sys
import io

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

n, m = map(int, input().split())
n_list = [input().split()[0] for _ in range(n)]
m_list = [input().split()[0] for _ in range(m)]
dif = n-m

ans = ""

class DropNest(Exception):
    pass 

try:
    for i in range(dif+1):
        for j in range(dif+1):
            target = n_list[i][j:j+m]
           
            if target != m_list[0]:
                continue
            else:
                cnt = 0
                for k in range(m):
                    target_h = n_list[i+k][j:j+m]
                    if target_h == m_list[k]:
                        cnt+=1
                if cnt==m:
                    ans="Yes"
                    raise DropNest
    print("No")
except DropNest:
    print(ans)




Measured memory_bytes: 3064
n = int(input())
plist = list(map(int, input().split()))

slist = sorted(plist)
if plist == slist:
    print("YES")
    exit()
cnt =0
for i in range(1,n+1):
    if cnt >= 3:
        print("NO")
        exit()
    elif i != plist[i-1]:
        cnt += 1
print("YES")

Measured memory_bytes: 3060
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int s = 10;
        int[][] map = new int[s][s];
        int[] dx = {0,-1,1,0,0,-1,-1,1,1,-2,0,0,2};
        int[] dy = {0,0,0,-1,1,-1,1,-1,1,0,-2,2,0};
        int[] size = {5,9,13};
        while(scan.hasNext()){
        	String[] com = scan.nextLine().split(",");
        	int x = Integer.parseInt(com[0]);
        	int y = Integer.parseInt(com[1]);
        	int t = Integer.parseInt(com[2]) - 1;
        	for(int i = 0;i < size[t];i++){
        		if(x+dx[i] >= 0 && x+dx[i] < s && y+dy[i] >= 0 && y+dy[i] < s){
        			map[y+dy[i]][x+dx[i]] += 1;
        		}
        	}
        }
        int max = 0;
        int count = 0;
        for(int i = 0;i < s;i++){
        	for(int j = 0;j < s;j++){
        		max = Math.max(max,map[i][j]);
        		count += (map[i][j] > 0)?0:1;
        	}
        }
        System.out.println(count + "\n" + max);
    }
}

Measured memory_bytes: 17188
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;

int main() {
	ll N;
	vector<ll>a;
	cin >> N;
	ll c;
	map<ll,ll > value;
	ll joker = 0;
	ll color = 0;
	for (ll i = 0; i < N; i++) {

		cin >> c;
		a.push_back(c);

	}
	for (ll i =0; i<N;i++) {
		if (a[i] / 400 >= 8) {
			joker++;

		}
		else {
			value[a[i]/400]++;
		}

	}
	for (ll i = 0; i <= 7; i++) {
		if (value[i] != 0) {

			color++;

		}
		
	}
	if (color == 0) {

		cout <<1<<" ";
		
	}
	else {
		cout << color<<" ";
	}
	color += joker;
	/*if (color >= 9) {

		color = 8;
	}*/
	cout << color;

}

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

int main() {
	int n;
	cin >> n;
	int x;
	double ans = 0;
	for(int i=1;i<=n;i++) {
		scanf("%d",&x);
		ans += 1.0/x;
	}
	ans = 1/ans;
	printf("%.6lf",ans);
	return 0;
}

Measured memory_bytes: 256
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
int main()
{
	sync;
	ll n,ind=1,cnt=1,ans=1;
	string s;
	cin>>n>>s;
	ll arr[26];
	for(ll i=0;i<26;i++)arr[i]=1;
	for(ll i=0;i<n;i++)
	arr[s[i]-'a']++;
	for(ll i=0;i<26;i++)
	ans=(ans*arr[i])%mod;
	cout<<ans-1<<endl;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

H,W = map(int,input().split())
for h in range(H):
    words = input().split()
    for w, word in enumerate(words):
        if word == 'snuke':
            print('{}{}'.format(chr(ord('A')+w), h+1))
    


Measured memory_bytes: 3064
from bisect import bisect_left, bisect_right
from operator import itemgetter
import sys
input = sys.stdin.readline


def main():
    N, Q = map(int, input().split())
    constructions = [None] * N
    for i in range(N):
        S, T, X = map(int, input().split())
        constructions[i] = (S, T, X)
    constructions.sort(key=itemgetter(2))
    D = [int(input()) for _ in range(Q)]
    ans = [-1] * Q
    nxt = list(range(1, Q+1))
    for S, T, X in constructions:
        l = bisect_left(D, S-X)
        r = bisect_right(D, T-X-1)
        idx = l
        while idx < r:
            if ans[idx] == -1:
                ans[idx] = X
            nidx = nxt[idx]
            nxt[idx] = max(nxt[idx], r)
            idx = nidx
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 94812
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 100000000000000001 // 1e17+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int d[33][33],cc[555][555];
ll costs[33][4];
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n,c;cin>>n>>c;
  for(int i=1;i<=c;i++)for(int j=1;j<=c;j++)cin>>d[i][j];
  for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>cc[i][j];

  for(int i=1;i<=c;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
        if((j+k)%3==0){
          costs[i][0]+=d[cc[j][k]][i];
        }
        if((j+k)%3==1){
          costs[i][1]+=d[cc[j][k]][i];
        }
        if((j+k)%3==2){
          costs[i][2]+=d[cc[j][k]][i];
        }
      }
    }
  }
  ll minn=INF;
  for(int i=1;i<=c;i++){
    for(int j=1;j<=c;j++){
      for(int k=1;k<=c;k++){
        if(j==i)continue;
        if(k==i)continue;
        if(k==j)continue;
        minn=min(minn, costs[i][0]+costs[j][1]+costs[k][2]);
      }
    }
  }

  P(minn);
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

int main()
{
    string X;
    cin >> X;
    stack<char> S;
    rep(i,X.size())
    {
        if(X[i]=='S')
        {
            S.push('S');
        }
        else if (X[i]=='T')
        {
            if (S.empty() or S.top() == 'T')
            {
                S.push('T');
            }
            else if (S.top()=='S')
            {
                S.pop();
            }
        }
        
    }
    cout << S.size();
    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using s64 = int64_t;
using u64 = uint64_t;

int main() {
	u64 N;
	cin >> N;
	
	string S;
	cin >> S;
	
 	vector<vector<u64>> RGB(3, vector<u64>(N+1));
	
	for(s64 i=N-1; i>=0; i--) {
		RGB[0][i] = (S[i] == 'R') ? RGB[0][i+1] + 1 : RGB[0][i+1]; 
		RGB[1][i] = (S[i] == 'G') ? RGB[1][i+1] + 1 : RGB[1][i+1]; 
		RGB[2][i] = (S[i] == 'B') ? RGB[2][i+1] + 1 : RGB[2][i+1];
	}
	
	u64 ans = 0;
	
	for(u64 i=0; i<N-2; i++) {
		char l = S[i];
		
		for(u64 j=i+1; j<N-1; j++) {
			if(S[j] == l) continue;
			
			char m = S[j];
			u64 d = j - i;
			char r;
			
			if(l != 'R' && m != 'R') {
				ans += RGB[0][j];
				r = 'R';
			} else if(l != 'G' && m != 'G') {
				ans += RGB[1][j];
				r = 'G';
			} else {
				ans += RGB[2][j];
				r = 'B';
			}
			
			if((j + d < N) && (r == S[j + d])) ans--;
			
		}
	}
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include<cstdio>
#include <iterator>
#include <sstream>
#include <algorithm>
#include <map>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
#define len(str) (int)(str.length())
int main() {
	int N;
	string S;
	cin >> N >> S;
	int max_ = 0;
	for (int a = 1; a < N; a++)
	{
		string X = S.substr(0, a);
		string Y = S.substr(a, N-a);
		int count = 0;
		for (char b='a';  b<='z'; b++)
		{
			if (X.find(b)!=string::npos && Y.find(b) != string::npos) {
				count++;
			}
		}
		max_ = max(max_,count);
	}
	cout << max_ << endl;
}

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

n = int(input())
a = list(map(int, input().split()))


minn = 10**10
cnt = 0
ans = 0
for i in range(n):
    temp = abs(a[i])
    minn = min(temp, minn)

    ans += temp

    if a[i]<0:
        cnt += 1



if cnt % 2 == 0:
    print(ans)
else:
    print(ans - 2*minn)

Measured memory_bytes: 14332
import math
def main():
  n = int(input())
  w = [input() for i in range(n)]
  flg=0
  
  for i in range(1,n):
    if w[i][0]!=w[i-1][len(w[i-1])-1]:
      flg=1
      break

  if flg==1 or len(set(w))!=n:
    print("No")
  else:
    print("Yes")
main()



Measured memory_bytes: 9176
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <climits>
#include <cstdint>
using namespace std;

inline namespace atcoder {
    template <typename T, size_t Depth>
    struct vector_helper { using type = vector<typename vector_helper<T, Depth - 1>::type>; };
    template <typename T>
    struct vector_helper<T, 0> { using type = T; };
    template <typename T, size_t Depth>
    using vector_t = typename vector_helper<T, Depth>::type;

    template <typename T> using vec = vector_t<T, 1>;
    template <typename T> using vvec = vector_t<T, 2>;
    template <typename T> using vvvec = vector_t<T, 3>;
}

int main() {
    int n; cin >> n;
    vec<int> cards(n);
    for (auto &e : cards) cin >> e;
    sort(cards.rbegin(), cards.rend());

    int alice = 0, bob = 0;
    for (int i = 0; i < n; i += 2) alice += cards[i];
    for (int i = 1; i < n; i += 2) bob += cards[i];

    cout << alice - bob << endl;
}



Measured memory_bytes: 3572
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
map<char,char>mp;
int main()
{
    mp['p']='q';
    mp['q']='p';
    mp['b']='d';
    mp['d']='b';
    char s[100010];
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++)
    {
        if(mp[s[i]]!=s[strlen(s)-i-1])return !printf("No");
    }
    return !printf("Yes");
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
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++)
typedef long long ll;

int main(){
	ll k;
	cin >> k;
	ll ans = 0;
	for (ll a = 1; a <= k; ++a) {
		for (ll b = 1; b <= k; ++b) {
			for (ll c = 1; c <= k; ++c) {
				ll temp = __gcd(a,b);
				temp = __gcd(temp, c);
				ans += temp;
			}
		}
	}
	cout << ans << endl;
    return 0;
}



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


class UnionFind
{
    private:
        std::vector<int> parent;  // parent[x]: x の根の番号
                                  //            x が根の場合はその連結成分の大きさ
        std::vector<int> rank;    // rank[x]  : x が属する木の高さ
        std::size_t sz;           // 連結成分の数

    public:
        // x が親の場合、parent[x] = -(その連結成分の大きさ)
        UnionFind( std::size_t n ): parent(n, -1), rank(n, 0), sz(n) {}

        // x が属する集合の親を返し、x を親に直接繋ぎ直す(経路圧縮)
        int find( int x )
        {
            if( parent[x] < 0 ) return x;
            else return parent[x] = find( parent[x] );
        }

        // x が属する集合と y が属する集合を統合する
        bool unite( int x, int y )
        {
            x = find( x );
            y = find( y );
            if( x == y ) return false;

            // 大きい方(x)に小さい方(y)を繋げる
            if( rank[x] < rank[y] ) std::swap( x, y );

            parent[x] += parent[y];  // x に連結している成分の大きさを更新する
            parent[y] = x;           // y を x に繋ぐ
            if( rank[x] == rank[y] ) rank[x]++;
            sz--;

            return true;
        }

        bool same( int x, int y ) { return find(x) == find(y); }
        std::size_t size()        { return sz; }
        std::size_t size( int x ) { return - parent[find(x)]; }
};


int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> p(N), x(M), y(M);
    for( int i = 0; i < N; i++ ){
        cin >> p[i];
        p[i]--;
    }
    for( int i = 0; i < M; i++ ){
        cin >> x[i] >> y[i];
        x[i]--, y[i]--;
    }


    UnionFind uni(N);
    for( int i = 0; i < M; i++ ) uni.unite( x[i], y[i] );

    int ans = 0;
    for( int i = 0; i < N; ++i ){
        if( uni.same( i, p[i] ) ) ++ans;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define int int64_t
#define double long double
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
#define all(v) v.begin(),v.end() 
using namespace std;
using pr = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

//プロトタイプ宣言

//グローバル変数
//const int INF = ;
//const int MAX_N = ;
//const int MAX_M = ;
const int mod = 1000000007;
//vvec dp(MAX_N, vec(MAX_M));

//関数：
struct mint {
	int x;
	mint(int x=0) : x((x%mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint &operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint &operator-=(const mint a) {
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint &operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res*=a;
	}
	mint pow(int t) const {
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}

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

struct Sieve {
	int n;
	vector<int> f, primes;
	Sieve(int n=1) : n(n), f(n+1) {
		f[0] = f[1] = -1;
		for(int i=2; i<=n; ++i) {
			if(f[i]) continue;
			primes.push_back(i);
			f[i] = i;
			for (int j=i*i; j<=n; j+=i) {
				if(!f[j]) f[j] = i;
			}
		}
	}

	bool isPrime(int x) {
		return f[x] == x;
	}
	vector<int> factorList(int x) {
		vector<int> res;
		while (x != 1) {
			res.push_back(f[x]);
			x /= f[x];
		}
		return res;
	}
	vector<pr> factor(int x) {
		vector<int> fl = factorList(x);
		if(fl.size() == 0) return {};
		vector<pr> res(1, pr(fl[0], 0));
		for(int p : fl) {
			if(res.back().first == p) {
				res.back().second++;
			} else {
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};

/* ユークリッドの互除法 */
int gcd(int x, int y) {
	if(x > y) swap(x, y);
 
	int ans;
	while(x > 0) {
		ans = x;
		x = y % x;
		y = ans;
	}
	return ans;
}

/* メイン・プログラム */
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n; cin >> n;
	vec a(n), b(n);
	rep(i, n) cin >> a[i];
	
	Sieve sieve(1e6);
	
	map<int,int> mp;
	rep(i, n) {
		auto f = sieve.factor(a[i]);
		for(auto p : f) {
			mp[p.first] = max(mp[p.first], p.second);
		}
	}
	
	mint lcm = 1;
	for(auto p : mp) {
		rep(i, p.second) {
			lcm *= p.first;
		}
	}
	
	mint ans;
	rep(i, n) {
		mint b = lcm/a[i];
		ans += b;
	}
	
	cout << ans.x << endl;
	return 0;
}

/*
pi を素数とし、X = ∏ pei , Y = ∏ pe′i と*1素因数分解されているとします (ei, e′i の一方は 0 i i ∏ max(ei,e′)
でもよい)。このとき、X と Y の最小公倍数は p i になります。このことを用いると、 i
A1, ..., AN の最小公倍数を素因数分解された形で求めることができます。
以上より、この問題は A = max Ai として、O(N √A) で解くことができました。また、適当な前
計算により素因数分解を高速化するなどの工夫により O(A + N log A) で求めることもできます。
*/


Measured memory_bytes: 9460
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type TupleInt struct {
	a int
	b int
	c int
	d int
}

func main() {
	sc := NewScanner()
	N, M, Q := sc.NextInt(), sc.NextInt(), sc.NextInt()
	T := make([]TupleInt, Q)
	for i := 0; i < Q; i++ {
		T[i] = TupleInt{sc.NextInt(), sc.NextInt(), sc.NextInt(), sc.NextInt()}
	}
	A := make([]int, N+1)
	var dfs func(c int, last int) int
	dfs = func(index int, last int) int {
		if index > N {
			sum := 0
			for i := 0; i < Q; i++ {
				if A[T[i].b]-A[T[i].a] == T[i].c {
					sum += T[i].d
				}
			}
			//fmt.Printf("%+v %d\n", A, sum)
			return sum
		}
		mx := 0
		for i := 0; i+last <= M; i++ {
			A[index] = last + i
			mx = max(mx, dfs(index+1, last+i))
		}
		return mx
	}
	fmt.Println(dfs(1, 1))
}

func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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

int main() {
    const df pi = 3.141592653589793238463;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll d, n;
    cin >> d >> n;
    ll sum = 0;
    while (n--) {
        ll t;
        cin >> t;
        sum += t;
    }
    if (sum > d) {
        cout << -1 << endl;return 0;
    }
    else
    cout << abs(d-sum) << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n, m;
	cin >> n >> m;
	priority_queue<int> q;
	vector<pair<int, int>> d(n);
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		d[i] = make_pair(a, b);
	}
	sort(d.begin(), d.end());
	long long sum = 0;
	int last_i = 0;

	for (int i = m-d[0].first; i >= 0; i--) {
		if (last_i < d.size()) {
			int cura = m-i;
			int j;
			for (j = last_i; j < d.size(); j++) {
				if (d[j].first != cura) {
					last_i = j;
					break;
				}
				q.push(d[j].second);
			}
			if (j == d.size())
				last_i = j;
		}
		if (!q.empty()) {
			auto e = q.top();
			q.pop();
			sum += (long long)e;
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 4692
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
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;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

int main(){
  double R;cin>>R;
  double t=M_PI;
  cout<<M_PI*2*R<<endl;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int x, a, b;
	cin >> x >> a >> b;

	if(abs(x-a) < abs(x-b)){
		puts("A");
	}else{
		puts("B");
	}

	return 0;
}


Measured memory_bytes: 768
N = int(input())
A = list(map(int, input().split()))

i = 0
j = 0
total = 0
count = 0
min = abs(A[0])

for i in range(N):
    total += abs(A[i])
    if A[i] < 0:
        count += 1
    if min > abs(A[i]):
        min = abs(A[i])

if count % 2 == 1:
    total = total - 2 * min

print(total)

Measured memory_bytes: 14284
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
using ll=long long;
int main()
{
    int n,rafi=0;
    cin>>n;
    int b=n;
    while(n!=0)
    {
        rafi=(rafi*10)+(n%10);
        n=n/10;
    }
   // if(n>0)
        //1 rafi=(rafi*10)+n;
    if(rafi==b)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	A, B := sc.nextInt()-1, sc.nextInt()-1
	var grid [100][100]rune
	for i := 0; i < 50; i++ {
		for j := 0; j < 100; j++ {
			grid[i][j] = '#'
		}
	}
	for i := 50; i < 100; i++ {
		for j := 0; j < 100; j++ {
			grid[i][j] = '.'
		}
	}
	for i := 0; i < 49 && A > 0; i++ {
		if i%2 != 0 {
			for j := 0; j < 100; j++ {
				grid[i][j] = '#'
			}
			continue
		}
		for j := 0; j < 100 && A > 0; j += 2 {
			if i%2 == 0 {
				grid[i][j] = '.'
			} else {
				grid[i][j+1] = '.'
			}
			A--
		}
	}
	for i := 51; i < 100 && B > 0; i++ {
		if i%2 == 0 {
			for j := 0; j < 100; j++ {
				grid[i][j] = '.'
			}
			continue
		}
		for j := 0; j < 100 && B > 0; j += 2 {
			if i%2 == 0 {
				grid[i][j] = '#'
			} else {
				grid[i][j+1] = '#'
			}
			B--
		}
	}
	fmt.Fprintln(wtr, 100, 100)
	for i := 0; i < 100; i++ {
		for j := 0; j < 100; j++ {
			fmt.Fprint(wtr, string(grid[i][j]))
		}
		fmt.Fprintln(wtr)
	}
}


Measured memory_bytes: 896