akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long in = sc.nextLong();
    int out = 0;
    for(int i = 1; i <= Math.sqrt(in); i++){
      if(in % i == 0){
        out = i;
      }
    }
    System.out.println(out + (in / out) - 2);
  }
}


Measured memory_bytes: 23124
program sample
    implicit none
  
    integer(8) :: i,j,m,n,h,w
    
    integer(8),allocatable :: a(:),y(:)
  
    read(*,*) n
    allocate(a(n))
    read(*,*)a
    w=1
    do i=1,n
        w=a(w)
        if (w==2)then
            write(*,*)i
            stop
        end if
    end do
    write(*,*)-1
    stop
end program sample
  



Measured memory_bytes: 1536
using System;

namespace ABC_139_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int i = 0;
            if (S[0] == T[0]) i += 1;
            if (S[1] == T[1]) i += 1;
            if (S[2] == T[2]) i += 1;
            Console.WriteLine(i);
        }
    }
}


Measured memory_bytes: 11092
#include <cmath>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n; double x[100000], y[100000];
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++)
    {
        scanf("%lf", &x[i]);
        scanf("%lf", &y[i]);
    }
    
    pair<double, double> p1[100000], p2[100000];
    
    for(int i = 0; i < n; i++)
    {
        p1[i] = make_pair(x[i], y[i]);
    }
    
    for(int i = 0; i < n; i++)
    {
        p2[i] = make_pair(y[i], x[i]);
    }
    
    sort(p1, p1 + n);
    sort(p2, p2 + n);
    
    double sqr_ans = 100000000.0;
    
    const int loops = 111;
    
    int n_1 = n - 1;
    
    for(int i = 0; i < n_1; i++)
    {
        int r = min(loops, n_1 - i);
        
        for(char j = 1; j <= r; j++)
        {
            double distance_ = (p1[i + j].first - p1[i].first) * (p1[i + j].first - p1[i].first) + (p1[i + j].second - p1[i].second) * (p1[i + j].second - p1[i].second);
        
            sqr_ans = min(distance_, sqr_ans);
        }
    }
    
    for(int i = 0; i < n_1; i++)
    {
        int r = min(loops, n_1 - i);
        
        for(char j = 1; j <= r; j++)
        {
            double distance_ = (p2[i + j].first - p2[i].first) * (p2[i + j].first - p2[i].first) + (p2[i + j].second - p2[i].second) * (p2[i + j].second - p2[i].second);
        
            sqr_ans = min(distance_, sqr_ans);
        }
    }
    
    printf("%.9f\n", sqrt(sqr_ans));
    
    return 0;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/*************************************************************************************/
void file(){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
/*************************************************************************************/

const ll maxn=2e5+1,mod=1e9+7;



int main(){

    sync
//    file();
    
    ll a;
    cin>>a;
    cout<<3*a*a<<endl;


  return 0;
}

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

int main(){
	priority_queue<int> Q;
	string word;
	while (cin >> word) {		
		if (word == "insert"){
			int num;
			cin >> num;
			Q.push(num);
		}
		else if (word == "extract"){
			int n = Q.top();
			Q.pop();
			cout << n << endl;
		}
		else break;
	}
}

Measured memory_bytes: 5976
#include <bits/stdc++.h>
#define pb push_back
#define pii pair <int, int>
#define mp make_pair
#define F first
#define S second
#define ll long long
#define iosbase ios_base::sync_with_stdio(false)
#define sc scanf
#define pr printf
#define null NULL
#define getcx getchar_unlocked
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define pll pair<ll,ll>
#define vi vector <int>
#define vll vector <ll>
 
#define maxs 200005
#define logmaxs 35
 
#define MOD 1000000007
#define eps 1e-9
#define llmax 1e18+5
#define intmax 1e9+5
#define intmin -intmax
 
#define pi 3.14159265358979
 
using namespace std;

ll a[2005];
ll dp[2005][2005];

int main(){
	iosbase;
	int n;
	ll x;
	cin>>n>>x;
	for(int i=0; i<n; i++)
		cin>>a[i];
	for(int j=0; j<n; j++){
		dp[0][j]=a[j];
	}
	for(int j=0; j<n; j++){
		dp[1][j]=a[(j-1+n)%n];
	}
	for(int i=2; i<=n-1; i++){
		for(int j=0; j<n; j++){
			dp[i][j]=min(dp[i-1][j], a[(j-i+n)%n]);
		}
	}
	ll ans=llmax;
	for(int j=0; j<=n-1; j++){
		ll sum=0;
		for(int i=0; i<n; i++){
			sum+=min(a[i], dp[j][i]);
		}
		sum+=(j*x);
		ans=min(ans, sum);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 31616
/*
ID: wangjun30
TASK:
LANG: C++
*/
#include<iostream>
using namespace std;
int numL[100010];
int numR[100010];
int answ[100010];
int main(){
	int Ll=0,Rl=0;
	string str;
	cin>>str;
	for(int i=0;i<str.size();i++){
		if(str[i]=='L'){
			Ll++;
			numL[i]=Ll;
		}
		else
			Ll=0;
	}
	for(int i=str.size()-1;i>=0;i--){
		if(str[i]=='R'){
			Rl++;
			numR[i]=Rl;
		}
		else
			Rl=0;
	}
	for(int i=0;i<str.size();i++){
		if(str[i]=='L'){
			if(numL[i]%2!=0)
				answ[i-numL[i]+1]++;
			else
				answ[i-numL[i]]++;
		}
		else{
			if(numR[i]%2!=0)
				answ[i+numR[i]-1]++;
			else
				answ[i+numR[i]]++;
		}
	}
	for(int i=0;i<str.size();i++)
		cout<<answ[i]<<' ';
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bs binary_search
#define pb push_back
#define pp pair<int,int>
#define F first 
#define S second 
#define lc "\n"
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
ll MAX=1e18 , MIN=-1e18 , MOD=1000000007;
int main()
{
    fastio
    char c; cin>>c;
    if(c>='A'&&c<='Z') cout<<'A';
    else cout<<'a';
    return 0;
}

Measured memory_bytes: 3652
x = int(input())

y = x//100

xx = x-y*100



for _ in range(y):
    if xx >= 5:
        xx -= 5
    elif xx >= 4:
        xx -= 4
    elif xx >= 3:
        xx-=3
    elif xx>=2:
        xx-=2
    elif xx >= 1:
        xx-=1
    else:
        xx=xx


if xx==0:
    print(1)
else:
    print(0)

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a <= b && b <= c){
        cout <<a<<" "<<b<<" "<<c<< endl;
    }
    else if (a <= c && c <= b){
        cout <<a<<" "<<c<<" "<<b<< endl;
    }
    else if (b <= a && a <= c){
        cout <<b<<" "<<a<<" "<<c<< endl;
    }
    else if (b <= c && c <= a){
        cout <<b<<" "<<c<<" "<<a<< endl;
    }
    else if (c <= a && a <= b){
        cout <<c<<" "<<a<<" "<<b<< endl;
    }
    else if (c <= b && b <= a){
        cout <<c<<" "<<b<<" "<<a<< endl;
    }
    return 0;
}


Measured memory_bytes: 3092
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=0
b=0
for i in range(N):
  if A[i]>B[i]:
    a+=A[i]-B[i]
  else:
    b+=(B[i]-A[i])//2
if b<a:
  print('No')
else:
  print('Yes')

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

vector<vector<int>> graph(11111);
vector<int> c;
vector<int> ans(11111,0);
int pos;

void DFS(int x){
	for(auto t:graph[x]){
		if(ans[t]==0){
			ans[t]=c[pos];
			pos++;
			DFS(t);
		}
	}
}

int main(){
	int N;
	cin >> N;
	for(int i=0;i<N-1;i++){
		int a,b;
		cin >> a >> b;
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	for(int i=0;i<N;i++){
		int C;
		cin >> C;
		c.push_back(C);
	}
	sort(c.begin(),c.end(),greater<int>());
	
	ans[0]=c[0];
	pos=1;
	DFS(0);
	
	cout << accumulate(c.begin()+1,c.begin()+N,0) << endl;
	for(int i=0;i<N;i++){
		cout << ans[i];
		if(i==N-1)cout << endl;
		else cout << " ";
	}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int n, p;
  while(scanf("%d%d", &n, &p) && n && p){
    vector<int>mayor(n);
    int i = 0, now = p;
    while(1){
      if(now){ mayor[i]++;now--;}
      else{ now = mayor[i];mayor[i] = 0;}
      if(mayor[i] >= p) break;
      i++;
      if(i == n) i = 0;
      //      rep(j, n) printf("%d ", mayor[j]);puts(""); 
    }

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

Measured memory_bytes: 1188
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;

int main() {
	int n;
	cin >> n;
	vi x(n), y(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	map<P, int> dp;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j)continue;
			int dx = x[i] - x[j];
			int dy = y[i] - y[j];
			dp[{dx, dy}]++;
		}
	}
	int res = n;
	for (auto it : dp) {
		res = min(res, n - it.second);

	}
	cout << res << endl;
}

Measured memory_bytes: 384
import java.util.*;

class Main {
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
int ans = K;
for(int i = 1;i < N;i++){
ans *= (K - 1);
}
System.out.println(ans);

}
}

Measured memory_bytes: 23124
from heapq import heappush, heappop, heapify
from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()
INF = 10**12
edges = defaultdict(lambda: defaultdict(lambda: INF))
n, m = map(int, input().split())
for i in range(m):
    a, b, c =map(int, input().split())
    edges[a-1][b-1] = (c, i)
    edges[b-1][a-1] = (c, i)

def dijkstra(s, n, w, cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    que = [[0, s]] # (dist, node_num)
    prev = {}
    heapify(que)
    while len(que) > 0:
        u_dist, u = heappop(que)
        #まだ使われてない頂点の中から最小の距離のものを探す
        for v in cost[u].keys():
            alt = d[u] + cost[u][v][0]
            edge_num = cost[u][v][1]
            if d[v] > alt:
                prev[v] = (u, edge_num)
                d[v] = alt
                heappush(que, [alt, v])
    cnt = defaultdict(int)
    for goal in range(s, n):
        if goal == s:
            continue
        u = goal
        while u != s:
            cnt[prev[u][1]] += 1
            u = prev[u][0]
    return cnt

ans = set()
cnt_paths = defaultdict(int)
for start in range(n-1):
    cnt = dijkstra(start, n, m, edges)
    for k, v in cnt.items():
        cnt_paths[k] += v
    ans = ans | set(cnt_paths.keys())
print(m - len(ans))



Measured memory_bytes: 53468
#include <stdio.h>
#include <string.h>
#include <vector>
#include <numeric>
#include <algorithm>
#include <functional>
#include <math.h>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

vector<int> primes;
#define MAX 1000010 
int tab[MAX];

void sieve() {
  for (int i=2;i<MAX;++i) {
    if (tab[i] == 0) {
      primes.push_back(i);
      for (int j=i;j<MAX;j+=i)
        tab[j] = 1;
    }
  }
}

vector<int> get_factorization(long long n) {
  vector<int> ret;

  for (auto& it : primes) {
    int cnt = 0;
    while (n % it == 0) {
      ++cnt;
      n/=it;
    }

    if (cnt) 
      ret.push_back(cnt);
  }

  if (n > 1) 
    ret.push_back(1);

  return ret;
}

int solve(int k) {
  for (int i=2;;++i) {
    if (k <= i) {
      return i - 1;
    }
    k -= i;
  }
}

int main() {
  sieve();

  long long n;
  scanf("%lld", &n);

  if (n == 1) {
    printf("0");
    return 0;
  }

  vector<int> fact = get_factorization(n);
  
  int ans = 0; 

  for (auto& it : fact) {
    ans += solve(it);
  }

  printf("%d", ans);

  return 0;
}


Measured memory_bytes: 7284
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 10007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};


// bool gousei(llong *x,llong *y){
//     if(*x<*y){
//         *y=x+y
//     }
// }

int main() {
	llong N,M;
	cin >> N >> M;
    LV koma(M);
    REP(i,M){
        cin >> koma[i];
    }
    llong cost = 0;
    LV L(M-1);
    sort(koma.begin(),koma.end(),greater<llong>());
    REP(i,M-1){
        L[i]=koma[i]-koma[i+1] ;
    }
    sort(L.begin(),L.end(),greater<llong>());
    if(N<M){
        REP(i,N-1){
            cost += L[i];
        }
        cost = koma[0] - koma[M-1]  - cost;
    }
    


    cout << cost << endl;





}


Measured memory_bytes: 1792
N = int(input())
txyn = [list(map(int, input().split())) for _ in range(N)]

def can_move(fr, to):
    from_t, from_x, from_y = fr
    to_t, to_x, to_y = to
    dist = abs(from_x - to_x) + abs(from_y - to_y)
    time = to_t - from_t
    if dist > time:
        return False
    return time%2 == dist%2

before_txy = (0, 0, 0)
for txy in txyn:
    if not can_move(before_txy, txy):
        print("No")
        break
    before_txy = txy
else:
    print("Yes")


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

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int N;
    cin >> N;
    for(int i=0; i<N; i++) for(int j=i+1; j<N; j++){
        int now = 0;
        while(nth_bit(i, now) == nth_bit(j, now)) now++;
        cout << now+1 << " \n"[j==N-1];
    }
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long int mod = 1e9;

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main(){
  long long int k, a, b; cin >> k >> a >> b;
  if(a <= b) {
    if(k <= a) {
      cout << 1 << endl;
      return 0;
    }
    cout << -1 << endl;
    return 0;
  }
  long long int num = 1;
  k -= a;
  num += ((k + (a-b) - 1) / (a-b)) * 2;
  cout << num << endl;

  return 0;
}


// EOF


Measured memory_bytes: 256
S = input()
N = len(S)
P = 2019

mod = 0
count = [0]* P
ten = 1
count[mod] += 1
for i in range(N):
    mod = (mod + int(S[N-i-1]) * ten) % P
    ten = ten * 10 % P
    count[mod] += 1

res = 0
for c in count:
    res += (c * (c - 1)) // 2

print(res)

Measured memory_bytes: 9232
#include<stdio.h>

int main(void)
{
	int i,j,ans;

	for(i=1;i<10;i++){
		for(j=1;j<10;j++){
			ans = i * j;
			
			printf("%dx%d=%d\n",i,j,ans);
			}
		}
	return 0;
}

Measured memory_bytes: 524
#include <stdio.h>

int main(){
	int i,j,num[10];
	char str[11];

	while(scanf("%s",str) != EOF){
		for(i = 0;i < 10;i++){
			num[i] = str[i]-'0';
		}

		for(i = 0;i < 9;i++){
			for(j = 0;j < 9-i;j++){
				num[j] = (num[j]+num[j+1])%10;
			}
		}

		printf("%d\n",num[0]);
	}

	return 0;
}

Measured memory_bytes: 540
x,y,z,K = map(int,input().split())
abc = [sorted(list(map(int,input().split())), reverse=True) for i in range(3)]

ans=[]
ab=[]

for i in range(x):
    for j in range(y):
        if (i+1)*(j+1) <= K:
            ab.append(abc[0][i]+abc[1][j])

ab.sort(reverse=True)

for i in range(min([len(ab),K])):
    for j in range(z):
        if (i+1)*(j+1) <= K:
            ans.append(ab[i]+abc[2][j])
    
ans.sort(reverse=True)

for i in range(K):
    print(ans[i])

Measured memory_bytes: 5364
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
vector<int> ans(20);
void dfs(vector<int> a,int b,int v){
  int k=0,i;
  for(i=1;i<10;i++){
    if(a[i]!=0){
      k=1;
      break;
    }
  }
  if(k==0 && v==0){
    ans[b]=1;
    return;
  }
  for(i=1;i<10;i++){
    if(a[i]>1 && v==1){
      a[i]=a[i]-2;
      v--;
      dfs(a,b,v);
      a[i]=a[i]+2,v++;
    }
    if(a[i]>0 && a[i+1]>0 && a[i+2]>0){
      a[i]--,a[i+1]--,a[i+2]--;
      dfs(a,b,v);
      a[i]++,a[i+1]++,a[i+2]++;
    }
    if(a[i]>2){
      a[i]=a[i]-3;
      dfs(a,b,v);
    }
  }
}
int main(){
  char s[15];
  while(scanf("%s\n",&s)!=EOF){
    vector<int> a(20);
    vector<int> b(20);
    int i;
    for(i=1;i<10;i++){
      ans[i]=0;
    }
    for(i=0;i<13;i++){
      a[s[i]-'0']++;
    }
    for(i=1;i<10;i++){
      b=a;
      b[i]++;
      if(b[i]>4){
        continue;
      }
      dfs(b,i,1);
    }
    int z=0;
    for(i=1;i<10;i++){
      if(z==0 && ans[i]==1){
        printf("%d",i);
        z=1;
      }
      else if(ans[i]==1){
        printf(" %d",i);
      }
    }
    if(z==0){
      printf("0");
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 3224
// 070-c
// lcmに罠あり


#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main(){
  ll N,A[107],g=1;cin >> N;
  rep(i,N){
    cin >> A[i];
    g=A[i]/gcd(A[i],g)*g;
  }
  cout << g << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main () {
int N,M;
cin >> N >> M;
int cnt = 0;
vector<int> vec(M);
for (int i = 0;i < M;i++) {
    cin >> vec.at(i);
    cnt += vec.at(i);
}
if (N - cnt <0) cout << -1 << endl;
else cout << N - cnt << endl;



return 0;
}

Measured memory_bytes: 3628
using System;

class main{
	static void Main(){
		string[] str = Console.ReadLine().Trim().Split(' ');
		int a = int.Parse(str[0]);
		int b = int.Parse(str[1]);
		if((a * b) % 2 == 1){
			Console.WriteLine("Odd");
		}else{
			Console.WriteLine("Even");
		}
	}
}

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

int main()
{
	int N;
	int a[110]={};
	int tmp,ans=1e7;
	
	cin >> N;
	for(int i=0;i<N;i++)
	{
		cin >> a[i];
	}
	
	for(int i=-100;i<=100;i++)
	{
		tmp=0;
		for(int j=0;j<N;j++)
		{
			tmp+=((i-a[j])*(i-a[j]));
		}
		ans=min(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}

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

template <typename T> class tRMQ {
  vector<T> data;
  T unit;

public:
  int n;
  function<T(const T &, const T &)> f;

  tRMQ(int _, T u, function<T(T, T)> bi) {
    unit = u;
    f = bi;
    n = 1;
    while (n < _) {
      n <<= 1;
    }
    data.resize(n * 4);
    for (int i = 0; i < 4 * n; i++)
      data[i] = unit;
  }

  tRMQ(vector<T> &v, T u, function<T(T, T)> bi) {
    unit = u;
    f = bi;
    n = 1;
    while (n < v.size())
      n <<= 1;
    data.resize(n * 4);
    for (int i = 0; i < n * 3; i++) {
      if (i < v.size())
        data[i + n] = v[i];
      else
        data[i + n] = u;
    }
    for (int i = n - 1; i >= 0; i--) {
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }

  void update(int index, T val) {
    int i = index + n - 1;
    data[i] = val;
    while (i > 0) {
      i = (i - 1) / 2;
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }

  // [a, b)
  T query(int a, int b, int k, int l, int r) {
    if (a < 0 || r <= a || b <= l) {
      return unit;
    }
    if (a <= l && r <= b) {
      return data[k];
    } else {
      return f(query(a, b, k * 2 + 1, l, (l + r) / 2),
               query(a, b, k * 2 + 2, (r + l) / 2, r));
    };
  }

  T query(int a, int b) { return query(a, b, 0, 0, n); }
};

int DAY = 86400;
int MOR = 10800;

int main() {
  int n;
  cin >> n;
  int base = 0;
  vector<ll> d(DAY);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    d[(base + a) % DAY] += 1;
    base += a + b;
    base %= DAY;
  }
  tRMQ<ll> q(d, 0ll, [](const ll &l, const ll &r) { return l + r; });
  ll ans = 0;
  for (int i = 0; i < DAY; i++) {
    ll b = q.query(max(-DAY + i, 0), max(-DAY + i + MOR + 1, 0)) +
           q.query(min(i, DAY), min(i + MOR + 1, DAY));
    ans = max(ans, b);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    vector<ll> a(n),b(n);
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        if(i==0) b[i]=a[i];
        else b[i]=b[i-1]+a[i];
        sum+=a[i];
    }
    ll ans=INFINITY;
    rep(i,n-1){
        ll abso=abs(b[i]-(sum-b[i]));
        ans=min(ans,abso);
    }
    cout<<ans;
}

Measured memory_bytes: 6348
s = input()
t = input()

dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i][j + 1], dp[i + 1][j])

n, m = len(s), len(t)
ans = ""
while n != 0 and m != 0:
    if dp[n][m] == dp[n-1][m]:
        n -= 1
    elif dp[n][m] == dp[n][m-1]:
        m -= 1
    else:
        n -= 1
        m -= 1
        ans = s[n] + ans
print(ans)

Measured memory_bytes: 112220
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
cnt[0] = 1
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = 0
for i in range(MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

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

int main(){
    int N, P;
    while(true){
        scanf("%d%d", &N, &P);
        if(N == 0 && P == 0) break;
        int c[50], left = P;
        fill(c, c + N, 0);
        int turn = 0;
        while(true){
            if(left == 0){
                left += c[turn];
                c[turn] = 0;
            }else{
                --left;
                c[turn] += 1;
            }
            if(c[turn] == P){
                break;
            }
            turn = (turn + 1) % N;
        }
        printf("%d\n", turn);
    }
    return 0;
}

Measured memory_bytes: 1188
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main(){
   int n, x, cnt=0, j=0;
   cin >> n >> x;
   vector<int> a(n);
   REP(i,n){
       cin >> a[i];
   }
   sort(a.begin(), a.end());
   while(cnt<=x&&j<n){
       cnt+=a[j];
       j++;
       //cout << j << endl;
   }
   if(cnt>x) j--;
   if(cnt<x&&j==n) j--;
   cout << j << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a[5];
	int b;
	int i;
	int j;
	for(i = 0; i < 5; i++){
		scanf("%d", &a[i]);
	}
	for(i = 0; i < 5; i++){
		for(j = i + 1; j < 5; j++){
			if(a[i] < a[j]){
				b = a[i];
				a[i] = a[j];
				a[j] = b;
			}
		}
	}
	printf("%d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[4]);
	return 0;
}

Measured memory_bytes: 596
import re

question1 =int(input())
question2 =input()
question3 =int(input())
question5 =input()


S = re.split(r' ',question2)
S=list(map(int, S))

T = re.split(r' ',question5)
T=list(map(int, T))

if (question1==0) or (question3==0):
    print(0)
else:
    S = set(S)
    T = set(T)
    matched_list = list(S & T)
    print(len(matched_list))


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i32 n; cin >> n;
    string s; cin >> s;

    vi  rs(n+1), gs(n+1), bs(n+1), emp;
    for(i32 i = 0; i < n; ++i) {
        rs[i+1] += rs[i] + (s[i] == 'R'? 1 : 0);
        gs[i+1] += gs[i] + (s[i] == 'G'? 1 : 0);
        bs[i+1] += bs[i] + (s[i] == 'B'? 1 : 0);
    }
//    cout << rs[n] + gs[n] + bs[n] << '\n';

    i64 cnt = 0;
    for(i32 i = 0; i < n-2; ++i) {
        for(i32 j = i + 1; j < n-1; ++j) {
            vi &csum = (s[i] == 'R' && s[j] == 'G' ?
                    bs : s[i] == 'G' && s[j] == 'R' ?
                    bs : s[i] == 'R' && s[j] == 'B' ?
                    gs : s[i] == 'B' && s[j] == 'R' ?
                    gs : s[i] == 'G' && s[j] == 'B' ?
                    rs : s[i] == 'B' && s[j] == 'G' ?
                    rs : emp);

            if(csum.empty()) continue;
            cnt += csum[n] - csum[j+1];
            i32 dist = j-i;
            if(j + dist < n && s[j + dist] != s[j] && s[j + dist] != s[i]) {
                cnt -= 1;
            }
        }
    }

    cout << cnt << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3680
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, L;
  cin>>N>>L;
  vector<string> S(N);
  for(int i=0;i<N;++i) cin>>S[i];
  sort(S.begin(), S.end());
  for(int i=0;i<N;++i) cout<<S[i];
  cout<<endl;
}



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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long A, long long B, long long K){
    if(A>K){
        cout<<A-K<<" "<<B<<endl;
    }else if(A+B>K){
        cout<<"0 "<<A+B-K<<endl;
    }else{
        cout<<"0 0"<<endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long K;
    scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	static final int MAX_NUM = 76543210;
	static final int NUM_BOARD = 8;
	char[] ans;

	void run() {
		Scanner scan = new Scanner(System.in);
		ans = new char[MAX_NUM + 1];
		bfs();
		while (scan.hasNext()) {
			char[] pazzle = new char[NUM_BOARD];
			for (int i = 0; i < NUM_BOARD; i++) {
				pazzle[i] = (char)scan.nextInt();
			}
			System.out.println((int)ans[convertArrayToNumber(pazzle)]);
		}
	}
	
	void bfs() {
		// ?§????(??\???)????????????(01234567)??§??????????????????????§??????§?????????
		// ????????????????????????????????¨???????§???????????????¢?????¨??????????????????
		Queue<char[]> que = new LinkedList<char[]>();
		que.add(new char[] { 0, 1, 2, 3, 4, 5, 6, 7 });
		while (!que.isEmpty()) {
			int size = que.size();
			for (int i = 0; i < size; i++) {
				char[] p = que.poll();
				int num = convertArrayToNumber(p);
				int index = getZeroOfIndex(p);
				int[] d = { -4, -1, 1, 4 };
				for (int j = 0; j < d.length; j++) {
					int ni = index + d[j];
					if (ni < 0 || ni >= NUM_BOARD) continue;
					if (index == 4 && d[j] == -1)  continue;
					if (index == 3 && d[j] == 1)   continue;

					char[] np = p.clone();
					swap(np, ni, index);
					int n = convertArrayToNumber(np);
					if (ans[n] != 0)
						continue;
					if (ans[n] == 0 && n == 1234567)
						continue;
					ans[n] = (char)(ans[num] + 1);
					que.add(np);
				}
			}
		}
	}

	void swap(char[] array, int a, int b) {
		char tmp = array[a];
		array[a] = array[b];
		array[b] = tmp;
	}

	int convertArrayToNumber(char[] array) {
		int sum = 0;
		for (int i = 1; i <= NUM_BOARD; i++) {
			sum += array[i - 1] * Math.pow(10, NUM_BOARD - i);
		}
		return sum;
	}

	int getZeroOfIndex(char[] array) {
		for (int i = 0; i < array.length; i++) {
			if (array[i] == 0)
				return i;
		}
		return -1;
	}

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

Measured memory_bytes: 189812
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const int INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
int a[6];
int main()
{
    cin>>a[1]>>a[2]>>a[3];
    sort(a+1,a+4);
    cout<<a[1]+a[2];
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static long MOD = (long)Math.pow(10, 9) + 7;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    long[] kai = new long[5000001];
    kai[0] = 1;
    for(long i = 1; i < 5000001; i++) {
      kai[(int)i] = (i * kai[(int)(i - 1)]) % MOD;
    }
    long ans = 0;
    for(int k = 0; k <= n; k++) {
      long t1 = kai[n];
      t1 = (t1 * func(kai[n - k], MOD - 2)) % MOD;
      t1 = (t1 * func(kai[k], MOD - 2)) % MOD;
      long t2 = kai[m];
      t2 = (t2 * func(kai[m - k], MOD - 2)) % MOD;
      long t3 = kai[m - k];
      t3 = (t3 * func(kai[m - n], MOD - 2)) % MOD;
      t3 = (t3 * t3) % MOD;
      long t = (t1 * t2) % MOD;
      t = (t * t3) % MOD;
      if((k % 2) == 0) {
        ans = (ans + t) % MOD;
      } else {
        ans = (ans - t + MOD) % MOD;
      }
    }
    System.out.println(ans);
  }

  public static long func(long a, long x) {
    if(x == 0) return 1;
    if((x % 2) == 0) {
      long t = func(a, x / 2);
      return (t * t) % MOD;
    } else {
      return (a * func(a, x - 1)) % MOD;
    }
  }
}


Measured memory_bytes: 76964
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,m,x;
  cin>>n>>m;
  vector<bool>a(100009,false);
  long long int b[n+1];
  for(long long int i=0;i<m;i++){
    cin>>x;
    a[x]=true;
  }
    b[1] = 1;
    b[2] = 2;
    if(a[1]==true){
        b[1] = 0;
        b[2] = 1;
    }
    if(a[2] == true){
        b[2] = 0;
    }
   for(long long int i=3;i<=n;i++){
        //cout<<a[i]<<endl;
    if(a[i]==true){
             b[i]=0;
    }
    else{
        b[i]=b[i-1]+b[i-2];
   b[i]=b[i]%1000000007;
        //cout<<i<<" "<<b[i]<<endl;
    }
   }
   cout<<b[n]%1000000007<<endl;
}

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


int main(){
    int x;
    cin >> x;
    map<int,int> m;
    m[1]++;
    for(int i=2;i<=31;i++){
        bool ok = true;
        int j = 2;
        while(ok){
            m[pow(i,j)]++;;
            if(pow(i,j) > 1000){
                ok = false;
            }
            j++;
        }
    }
    int n = m.size();
    vector<int> a;
    for(auto x:m){
        a.push_back(x.first);
    }
    sort(a.begin(),a.end());


    for(int i=0;i<n;i++){
        if(a[i] > x){
            cout << a[i-1] << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 384
s = input()
n = len(s)

ans = 0
cnt = 0

for i in range(n-1):
    if s[i] == "A":
        cnt += 1
    if s[i]+s[i+1] == "BC":
        ans += cnt
    if s[i]+s[i+1] in ("AC","BA","BB","CC"):
        cnt = 0

print(ans)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
// ==================================================
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,a,b) for(i64 i=(int64_t)(a);i<(int64_t)(b);i++)
#define repn(i,n) rep(i,0,n)
#define din(t, ...) t __VA_ARGS__;_din(__VA_ARGS__)
#define v(t,n) vector<t> n
void _din() {}
void dout() { cout << endl; }
template <typename T, typename ... Args> inline void _din(T& head, Args& ... rest) { cin >> head; _din(rest...); }
template <typename T, typename ... Args> inline void dout(T head, Args ... rest) { cout << head; if (sizeof...(rest)) cout << ' '; dout(rest...); }
template <typename T>inline void qsortv(vector<T>& v) { qsort(v.data(), v.size(), sizeof(T), [](const void*a, const void*b)->int {if ((*(T*)a) < (*(T*)b))return -1; if ((*(T*)a) == (*(T*)b))return 0; return 1; }); }
template <typename T, typename F>inline void qsortv(vector<T>& v, F func) { qsort(v.data(), v.size(), sizeof(T), func); }
template <typename T>inline void sortv(vector<T>& v) { sort(v.begin(), v.end()); }
// ==================================================

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

	dout(n - i + 1);
}

Measured memory_bytes: 256
import sys
import itertools
input = sys.stdin.readline
n,k,q=map(int,input().split())
A=[int(input()) for _ in range(q)]

ans=[k]*n
for i in range(q):
  ans[A[i]-1]+=1
for i in range(n):
  if ans[i]-q>0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 10480
def abc111(N: int) -> int:
    d = N // 100
    n1 = d * 111
    n2 = (d+1) * 111

    if N <= n1:
        return n1
    return n2


if __name__ == "__main__":
    N = int(input())
    ans = abc111(N)
    print(ans)


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main(){
  long long int n,k;
  cin>>n>>k;
  long long int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  long long int ans=0,l,mina=10000;
    for(int j=0;j<k;j++){
      for(int i=0;i<n;i++){
       
        if(mina>a[i]){
        mina=a[i];
        l=i;
        }
      }
      ans+=mina;
      a[l]=10000;
      mina=10000;
    }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lli long long int
using namespace std;

int main() {
	fastio;
	int a;
	cin >> a;

	int ans = a + (a * a) + (a * a * a);
	cout << ans << endl;
	return 0;
}

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

int main(void) {
    int n;
    int *w, *sum;
    int i;

    scanf("%d", &n);

    w = calloc(n, sizeof(int));
    sum = calloc(n-1, sizeof(int));

    for (i = 0; i < n; i++) 
        scanf("%d", &w[i]);

    int t = 0;
    
    for (t = 0; t < n-1; t++) {
        int a = 0, b = 0;
        for (i = 0; i <= t; i++) {
            a += w[i];
        }
        for (; i < n; i++) {
            b += w[i];
        }
        sum[t] = abs(a - b);
    }

    int min = sum[0];

    for (i = 1; i < n-1; i++) {
        if (min > sum[i])
            min = sum[i];
    }

    printf("%d\n", min);

    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<long long> a(N);
    for(int i=0;i<N;i++){
        long long b;
        cin >> b;
        a[i] = b;
    }

    sort(a.begin(),a.end());
    int ptr=0;
    int total=0;
    while(ptr<N){
        long long tmp=a[ptr];
        int f=0;
        while(tmp==a[ptr] && ptr<N){
            ptr++;
            f++;
        }
        total += f%2;
    }

    cout << total << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
    string s;
    cin >> s;
    int date = 0;
    int m_date = 0;
    rep(i, 3){
        if(s[i] == 'S'){
            date = 0;
            m_date = max(date, m_date);
        }
        if(s[i] == 'R'){
            date++;
            m_date = max(date, m_date);
        }
    }
    cout << m_date << endl;

}

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

typedef long long ll;
typedef long double ld;
 

bool checkany(vector<bool> lst){
	bool ans = false;
	for (int i = 0; i < lst.size(); i++){
		if (lst[i]) ans = true;
		if (ans) break;
	}
	return ans;
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin >> n;
	
	int C[n], S[n], F[n];

	for (int i = 1; i < n; i++){
		cin >> C[i] >> S[i] >> F[i];
	}
	
	int T[n];
	memset(T,0, sizeof(T));
	int track[n];
	
	for (int i = 0; i < n; i++){
		track[i] = i;
	}
	
	vector<bool> not_done(n, true);
	not_done[0] = false;
	
	bool travel[n];
	memset(travel, false, sizeof(travel));
	
	int timeBefore[n];
	memset(timeBefore, 0, sizeof(timeBefore));
	
	while (checkany(not_done)){
		for (int i = 1; i < n; i++){
			if (not_done[i]){
				if (!travel[i]){
					if (T[i] < S[track[i]]) T[i]++;
					else if (T[i] == S[track[i]]){
						travel[i] = true;
						timeBefore[i] = T[i];
					}
					else{
						if (T[i] % F[track[i]] != 0) T[i]++;
						else{
							travel[i] = true;
							timeBefore[i] = T[i];
						}
					}
				}
				
				if (travel[i]){
					if (T[i]-timeBefore[i] < C[track[i]]) T[i]++;
					else{
						travel[i] = false;
						track[i]++;
					}
				}
				
				if (track[i] == n) not_done[i] = false;
			}
		}
	}
	
	for (int i = 1; i < n; i++){
		cout << T[i] << endl;
	}
	cout << 0 << endl;

}

Measured memory_bytes: 256
import sys
import math
DH = {i: i * 30 % 360 for i in range(12)}
DM = {i: i * 5.5 % 360 for i in range(60)}
A,B,H,M = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
RH = DH[H]
RM = DM[M]
D = max(RH - RM, RM - RH)
C = min(D, 360 - D)
Y = math.pi * (C / 180.0)
a = math.sqrt((A ** 2) + (B ** 2) - ((2 * A * B) * math.cos(Y)))
print(a)


Measured memory_bytes: 9528
package main

import (
	"fmt"
)

func Reverse(s string) string {

	runes := []rune(s)

	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}

	return string(runes)
}

func main() {

	var S string
	fmt.Scanf("%s", &S)

	N := len(S)

	if (S == Reverse(S)) && (S[0:(N-1)/2] == Reverse(S[0:(N-1)/2])) && (S[(N+3)/2-1:N] == Reverse(S[(N+3)/2-1:N])) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1848
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


signed main(void){
    int M;
    int d[214514],c[214514];
    cin >> M;
    REP(i,M){
        cin >> d[i] >> c[i];
    }
    int Ans=0;
    vector<int> D,E;
    REP(i,M){
        E.clear();
        
        int cf=c[i],df=d[i];
        
        while(cf>=10){
            Ans+=(cf/10)*(df+9);
            cf=(cf/10)+(cf%10);
            //cout << cf << endl;
        }
        
        REP(i,cf){
            E.push_back(df);
        }
        while(E.size()>=2){
            int p,q;
            p=E[E.size()-1];E.pop_back();
            q=E[E.size()-1];E.pop_back();
            if(p+q<10){
                E.push_back(p+q);
            }else{
                E.push_back(1);
                E.push_back(p+q-10);
            }
            Ans++;
        }
        
        if(E.size()>=1){
            D.push_back(E[0]);
        }else{
            D.push_back(0);
        }
    }
    
    //REP(i,D.size()){cout << D[i];}
    //cout << endl << Ans << endl;
    
    while(D.size()>=2){
        
        //REP(i,D.size()){cout << D[i];}cout << endl;
        
        int p,q;
        p=D[D.size()-1];D.pop_back();
        q=D[D.size()-1];D.pop_back();
        if(p+q<10){
            D.push_back(p+q);
        }else{
            D.push_back(1);
            D.push_back(p+q-10);
        }
        Ans++;
        
        
    }
    cout << Ans << endl;
    return 0;
}



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


    class Program
    {
        static void Main(string[] args)
        {
            string Input = Console.ReadLine();
            string n = Input.Substring(Input.Length - 1);
            if(n == "3"){
            Console.WriteLine("bon");
            }else if(n == "0" || n == "1" || n == "6" || n == "8"){
                Console.WriteLine("pon");
            }
            else{
                Console.WriteLine("hon");
            }
        }
    }

Measured memory_bytes: 17340
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define lower(a) transform(a.begin(), a.end(), a.begin(), ::tolower)
#define upper(a) transform(a.begin(), a.end(), a.begin(), ::toupper)
//#define min(a) *min_element(a.begin(),a.end())
//#define max(a) *max_element(a.begin(),a.end())
#define pdd pair<long double, long double>
#define prnt(a)      \
	for (auto x : a) \
		cout << x << " ";
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define PI 3.1415926535897932385
#define INF 1000000000000000
#define M 1000000007
#define ve vector<ll>;
vector<vector<ll>> a(1e5 + 1, vector<ll>(3));
vector<vector<ll>> dp(1e5 + 1, vector<ll>(3, -1));
ll n;
ll fun(ll i, ll p)
{
	if (i > n - 1)
	{
		return 0;
	}
	if (dp[i][p] != -1)
	{
		return dp[i][p];
	}

	if (p == 0)
	{
		return dp[i][p] = max(fun(i + 1, 1) + a[i][1], fun(i + 1, 2) + a[i][2]);
	}
	if (p == 1)
	{
		return dp[i][p] = max(fun(i + 1, 0) + a[i][0], fun(i + 1, 2) + a[i][2]);
	}
	if (p == 2)
	{
		return dp[i][p] = max(fun(i + 1, 1) + a[i][1], fun(i + 1, 0) + a[i][0]);
	}
}
int main()
{

	cin >> n;
	for (ll i = 0; i < n; i++)
	{
		for (ll j = 0; j < 3; j++)
		{
			cin >> a[i][j];
		}
	}

	ll f1, f2, f3;
	f1 = fun(0, 0);
	f2 = fun(0, 1);
	f3 = fun(0, 2);
	cout << max(f1, max(f3, f2)) << endl;
	return 0;
}


Measured memory_bytes: 18832
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int n;
int ar[N];
int pr[N][20];

bool can(int mid , int idx){
     for(int i = 0; i < 20; i++){
        if(pr[mid][i] - pr[idx - 1][i] > 1)
            return 0;
     }
     return 1;
}

int main(){
    scanf("%d" , &n);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &ar[i]);
        for(int j = 0; j < 20; j++){
            pr[i][j] = pr[i - 1][j] + ( (ar[i] & (1 << j)) != 0);
        }
    }
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        int l = i , r = n;
        while(l < r){
            int mid = (l + r + 1) >> 1;
            if(can(mid , i)){
                l = mid;
            } else {
                r = mid - 1;
            }
        }
        ans += l - i + 1;
    }
    printf("%lld\n" , ans);
}

Measured memory_bytes: 16640