akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int, int> PA;
typedef map<PA, int> MA;


MA mp;
int a, b, h, w, n;
int dx[] = {0, 1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 0, -1, -1, -1, 0, 1, 1, 1};

signed main()
{
    cin >> h >> w >> n;
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        for(int j = 0; j < 9; j++){
            mp[PA(a + dx[j], b + dy[j])]++;
            //printf("%d %d %d\n", a + dx[j], b + dy[j], mp[PA(a + dx[j], b + dy[j])]);
        }
    }
    MA :: iterator ite;
    int sum = 0;
    for(ite = mp.begin(); ite != mp.end(); ite++){
        if(1 < ite -> first.first && ite -> first.first < h && 1 < ite -> first.second && ite -> first.second < w)
            if(ite -> second > 0){
                sum++;
        }
    }
    cout << (h - 2) * (w - 2) - sum << endl;

    for(int j = 1; j < 10; j++){
        int ans = 0;
        for(ite = mp.begin(); ite != mp.end(); ite++){
            if(1 < ite -> first.first && ite -> first.first < h && 1 < ite -> first.second && ite -> first.second < w)
            if(ite -> second == j){
                ans++;
            }
        }
        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 56448
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long intS
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    int d;
    
    cin >> d;
    
    if (d == 25){
    
    cout << "Christmas" << endl;
    
    }else if (d == 24){
    
    cout << "Christmas Eve" << endl;
    
    }else if(d == 23){
    
    cout << "Christmas Eve Eve" << endl;
    
    }else if(d == 22){
    
    cout << "Christmas Eve Eve Eve" << endl;
    
    }
    
    
    
//////////////////////////////////////////////////////
return 0;}

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

int main(void)
{
    int n;
    char taro_animal[100];
    char hanako_animal[100];
    int taro_point = 0;
    int hanako_point = 0;

    scanf("%d", &n);

    for (int i = 0; i < n; i++)
    {
        scanf("%s %s", taro_animal, hanako_animal);
        int result = strcmp(taro_animal, hanako_animal);
        if (result < 0)
        {
            hanako_point += 3;
        }
        else if (result == 0)
        {
            taro_point += 1;
            hanako_point += 1;
        }
        else
        {
            taro_point += 3;
        }
    }

    printf("%d %d\n", taro_point, hanako_point);

    return 0;
}



Measured memory_bytes: 2040
#include<bits/stdc++.h>
using ll = int_fast64_t;

ll lcm(ll a, ll b){
	if(a==0) return b;
	else return a*b/std::__gcd(a, b);
}

int main(){
	ll n, m, ans = 0, prev = -1;
	scanf("%ld %ld", &n, &m);
	
	bool cant = false;
	for(ll i=0; i<n; i++){
		ll tmp;
		scanf("%ld", &tmp);
		ans = lcm(ans, tmp/2);
		
		ll cnt = 0;
		while(tmp%2==0) tmp/=2, cnt++;
		if(prev>=0 and prev!=cnt) cant = true;
		prev = cnt;
	}
	
	if(cant) puts("0");
	else printf("%ld\n", (m / ans + 1) / 2);
	return 0;
}


Measured memory_bytes: 384
N=int(input())
w=list(map(int,input().split()))
S=sum(w)
s=[]
X=[]
for t in range(1,N+1):
  s.append(w[t-1])
  a=sum(s)
  A=S-a
  x=abs(A-a)
  X.append(x)
print(min(X))

Measured memory_bytes: 3064
#include <iostream>

int area(int height, int width);
int perimeter(int height, int width);

int main()
{
	int a, b;
	std::cin >> a >> b;

	std::cout << area(a, b) << ' ' << perimeter(a, b) << std::endl;

	return 0;
}

int area(int height, int width)
{
	return height * width;
}

int perimeter(int height, int width)
{
	return (height + width) * 2;
}

Measured memory_bytes: 1160
import sys
import copy
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

x = I()

if(x >= 30):
    print('Yes')
else:
    print('No')

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

#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;

class Node {
public:
  int to;
  int dist;
  Node() {}
  Node(int _t,int _d) : to(_t),dist(_d){}
};

bool is_LPG[6001];
bool dp[6001][2001]; //dp[city_id][remaining_LPG] = dist;

int get_city_id(map<string,int>& cities,const string& city){
  if(cities.find(city) == cities.end()){
    int idx = cities.size();
    cities[city] = idx;
  }
  return cities[city];
}

class State {
public:
  int city_id;
  int dist;
  int remaining_LPG;
  State(int _city_id,int _dist,int _con){
    city_id = _city_id;
    dist = _dist;
    remaining_LPG = _con;
  }

  bool operator <(const State& s) const{
    return (dist < s.dist);
  }

  bool operator >(const State& s) const{
    return (dist > s.dist);
  }
};

int main(){
  int total_roads;
  int total_LPG_stations;
  int capacity;
  while(cin >> total_roads >> total_LPG_stations >>capacity){
    if(total_roads == 0
       && total_LPG_stations == 0
       && capacity == 0) break;

    map<string,int> cities;
    memset(is_LPG,false,sizeof(is_LPG));
    memset(dp,false,sizeof(dp));

    string src,dst;
    cin >> src >> dst;
    get_city_id(cities,src);
    get_city_id(cities,dst);

    vector<Node> nodes[6001];
    for(int road_idx = 0; road_idx < total_roads; road_idx++){
      string from_str,to_str;
      int dist;

      cin >> from_str >> to_str >> dist;
      int from_num = get_city_id(cities,from_str);
      int to_num = get_city_id(cities,to_str);

      nodes[from_num].push_back(Node(to_num,dist));
      nodes[to_num].push_back(Node(from_num,dist));
    }

    for(int LPG_idx = 0; LPG_idx < total_LPG_stations; LPG_idx++){
      string city;
      cin >> city;
      is_LPG[get_city_id(cities,city)] = true;
    }

    priority_queue<State,vector<State>, greater<State> > que;
    que.push(State(get_city_id(cities,src),0,10*capacity));

    int dst_id = get_city_id(cities,dst);

    int res = INF;

    while(!que.empty()){
      State s = que.top();
      que.pop();

      if(s.city_id == dst_id){
	res = s.dist;
	goto found;
      }

      if(dp[s.city_id][s.remaining_LPG]) continue;
      dp[s.city_id][s.remaining_LPG] = true;

      for(int to_idx=0;to_idx<nodes[s.city_id].size();to_idx++){
	int to = nodes[s.city_id][to_idx].to;
	int dist = nodes[s.city_id][to_idx].dist;
	if(s.remaining_LPG < dist) continue;

	int next_remaining_LPG = (is_LPG[to] ? 10 * capacity : s.remaining_LPG - dist);

	que.push(State(to,s.dist + dist,next_remaining_LPG));
      }
    }
  found:;
    printf("%d\n",res >= INF ? -1 : res);
  }
  return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC097A()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(c - a) <= d)
		cout << "Yes" << endl;
	else if (abs(b - a) <= d && abs(c - b) <= d)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}

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

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

using namespace std;

int main(void){
    string s;
    cin >> s;
    vector<int> a(26, 0);
    for(char c : s){
        a[c-'a']++;
    }
    for(int i : a){
        if(i >= 2){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int n;

const int N = 51;
ll s[N],p[N];

ll dfs(int lv, ll &r){
    if(s[lv]<=r){
        r -= s[lv];
        return p[lv];
    }

    if(r==0) return 0;

    ll ret = 0;
    --r;
    if(r==0) return ret;

    ret += dfs(lv-1,r);
    if(r==0) return ret;

    --r;
    ++ret;
    if(r==0) return ret;

    ret += dfs(lv-1,r);
    if(r==0) return ret;

    --r;
    return ret;
}

int main(){
    s[0] = 1;
    p[0] = 1;
    for(int i=1; i<N; ++i){
        s[i] = 2*s[i-1] + 3;
        p[i] = 2*p[i-1] + 1;
    }

    ll x;
    cin >>n >>x;
    cout << dfs(n,x) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
	int n;
	cin>>n;
	cout<<"ABC"<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

//求最大公约数
public class Main {
	private static int gcd(int x, int y) {
		if (x < y) {
			int t = x;
			x = y;
			y = t;
		}
		
		while (x % y != 0) {
			//System.out.println(x + " " + y);
			int r = x % y;
			x = y;//上一个除数做被除数
			y = r;//余数做除数
		}
		return y;
	}
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt() , y = scan.nextInt();
		System.out.println(gcd(x, y));
	}
}



Measured memory_bytes: 26420
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

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

    int n;cin>>n;
    vec l(n);
    rep(i,n) cin>>l[i];

    sort(l.begin(),l.end());
    int cnt=0;
    rep(i,n-2){
        for(int j=i+1; j<n-1; j++){
            for(int k=j+1; k<n; k++){
                if(l[i]>=l[j]+l[k]) break;
                if(l[j]>=l[i]+l[k]) break;
                if(l[k]>=l[j]+l[i]) break;
                cnt++;

            }
        }
    }

    cout<<cnt<<endl;
}

Measured memory_bytes: 3668
#include <iostream>
#include <fstream>

using namespace std;

void pp_seg(int *a,int a_size){
    for(int i=0;i<a_size;i++){
        cout << a[i];
        if(i!=a_size-1){
            cout << " ";
        }
    }
    cout << endl;
}

int maxSegment(int *a, int a_size){
    int ans = a[0];
    for(int i=0;i<a_size;i++){
        if(ans < a[i]){
            ans = a[i];
        }
    }
    return ans;
}

void swap(int *a, int *b){
    int temp = *a;
    *a = *b;
    *b = temp;
    return;
}

int partition(int *a,int a_size, int p, int r){
    int x = a[r];
    int i = p-1;
    for(int j=p;j<r;j++){
        if(a[j] <= x){
            i++;
            swap(a+i,a+j);
        }
    }
    swap(a+i+1,a+r);
    return i+1;
}

int main(){
    int n;
    cin >> n;
    int *a = new int[n];
    for(int i=0;i<n;i++) cin >> a[i];
    int based = partition(a,n,0,n-1);
    for(int i=0;i<n;i++){
        if(i!=based){
            cout << a[i];
        }else{
            cout << "[" << a[i] << "]";
        }
        if(i!=n-1){
            cout << " ";
        }else{
            cout << endl;
        }
    }
    delete [] a;
    return 0;
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){//桁数
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){//最小公倍数
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){//最大公約数
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  string s;
  cin>>s;
  int a=0;
  for(int i=0; i<3; i++){
    if(s[i]=='o')
      a++;
  }
  cout<<700+100*a<<endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <ctime>


#ifndef _USEFUL_MACROS_
#define _USEFUL_MACROS_
#define INF 99999999
#define N_PRIME 1000000007
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define OUTPUT_DEBUG
#ifdef OUTPUT_DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x) do{}while(false)
#endif
#endif 

using namespace std;

int main(void){
    int N,W;
    cin >> N >> W;
    int v[N];
    int w[N];
    int dp[W+1];
    
    REP(i,N){
        cin >> v[i] >> w[i];
    }
    
    REP(i,W+1)
        dp[i]=0;
    
    REP(i,N){
        FOR(j,w[i],W+1){
            dp[j] = max(dp[j],dp[j-w[i]]+v[i]);
        }
    }
    
    cout << dp[W] << endl;
    
    
    return 0;
}

Measured memory_bytes: 3108
N,D = map(int,input().split())
X_s = [list(map(int,input().split())) for _ in range(N)]
answer = 0
for i in range(N-1):
  for j in range(i+1,N):
    dist = 0
    for k in range(D):
      dist += abs(X_s[i][k] - X_s[j][k])**2
    if int(dist**0.5)**2 == dist:
      answer += 1
print(answer)

Measured memory_bytes: 3064
s = int(input())

# 0 0 1e9 1 y x
# 1e9 * x - y == s
# 1e9-y == s % 1e9 (mod 1e9)
# y == (1e9 - s % 1e9) % 1e9
# -yとs の　mod 1e9が等しいので最初の指揮
# 1e9 * x = s + y
# のs + yは1e9の倍数
don = 10 ** 9

y = (don - s % don) % don
x = (s + y) // don
print('0 0 {} 1 {} {}'.format(don, y, x))


Measured memory_bytes: 9088
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
double x[51], y[51];

double f2(double r, double c){
	double ret = 0;
	rep(i,n) chmax(ret, sqrt((x[i]-r)*(x[i]-r) + (y[i]-c)*(y[i]-c)));
	return ret;
}

double f1(double mid){
	double l = 0, r = 1000;
	rep(_,100){
		double mid1 = (l * 2 + r) / 3;
		double mid2 = (l + r * 2) / 3;
		if(f2(mid, mid1) < f2(mid, mid2)) r = mid2;
		else l = mid1;
	}
	return f2(mid, l);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	rep(i,n) cin >> x[i] >> y[i];
	double l = 0, r = 1000;
	rep(_,100){
		double mid1 = (l * 2 + r) / 3;
		double mid2 = (l + r * 2) / 3;
		if(f1(mid1) < f1(mid2)) r = mid2;
		else l = mid1;
	}
	double ans = f1(l);
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

int main(void){
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
        B[i] = A[i];
    }

    sort(B.begin(), B.end(), greater<int>());
    for(int i = 0; i < N; i++){
        if(A[i] == B[0]) cout << B[1] << '\n';
        else cout << B[0] << '\n';
    }

    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;
  return 0;
}

Measured memory_bytes: 3600
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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();

		char []a = new char [26];
		
		for(int i = 0 ; i < 26 ;i++) {
			a[i] = (char)('a'+ i);
		}
		int min = 1000000;
		
		for(int i = 0 ; i < 26 ;i++) {
			int temp = 0;
			List <Integer> l = new ArrayList <Integer>();
				for(int j = 0 ; j < n ;j++) {
					if(s.charAt(j) == a[i]) {
						l.add(j - temp);
						temp = j+1;
				}
			}
				l.add(n - temp);
				Collections.sort(l);
				min = Math.min(min, l.get(l.size()-1));
		}
		
		System.out.println(min);
	}

}


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

int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  for(int i = 0; i < n; i++){
    cin >> arr[i];
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      ans += arr[i] * arr[j];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;

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

    vector<pair<int, int>> A;
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        A.push_back(make_pair(a, b));
    }

    sort(A.begin(), A.end(), [](const auto &x, const auto &y) {
        return x.first < y.first;
    });

    int i = 0;
    while (K > 0) {
        K -= A[i].second;
        i++;
    }

    cout << A[i - 1].first << endl;
}

Measured memory_bytes: 4320
n=int(input())
a=list(map(int,input().split()))

accumlate=[0]
for i in range(n):
    accumlate.append(accumlate[-1]+a[i])

MIN=10**10
for g in range(1,n):
    MIN=min(MIN,abs(accumlate[-1]-2*accumlate[g]))

print(MIN)

Measured memory_bytes: 24824
#include<bits/stdc++.h>
using namespace std;
int main(){
   int i;
   int a[3];
   for(i=0;i<3;i++) cin>>a[i];
   sort(a,a+3);
   if(a[0]==5&&a[1]==5&&a[2]==7) cout<<"YES";
  else cout<<"NO";
   return 0;
}

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

#define MAX 100000
#define INF (1 << 30)

class Edge {
public:
	int t, w;

	Edge() {}
	Edge(int t, int w) :t(t), w(w) {}
};

vector<Edge> v[MAX];
int n, d[MAX];

bool flag[MAX];
int cnt;

void bfs(int s)
{
	for (int i = 0; i < n; i++) d[i] = INF;
	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	int u;
	while (!Q.empty())
	{
		u = Q.front(); Q.pop();
		for (int i = 0; i < v[u].size(); i++)
		{
			Edge e = v[u][i];
			if (d[e.t] == INF) {
				d[e.t] = d[u] + e.w;
				Q.push(e.t);
			}
		}
	}
}

void solve(void)
{
	bfs(0);

	int maxv = 0;
	int tgt = 0;
	for (int i = 0; i < n; i++)
	{
		if (d[i] == INF) continue;
		if (maxv < d[i]) {
			maxv = d[i];
			tgt = i;
		}
	}

	bfs(tgt);

	maxv = 0;
	for (int i = 0; i < n; i++)
	{
		if (d[i] == INF) continue;
		maxv = max(maxv, d[i]);
	}

	cout << maxv << endl;
}

int main(void)
{
	int s, t, w;
	cin >> n;

	for (int i = 0; i < n - 1; i++)
	{
		cin >> s >> t >> w;
		v[s].push_back(Edge(t, w));
		v[t].push_back(Edge(s, w));
	}

	solve();

	return 0;
}


Measured memory_bytes: 9796
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, A, B = list(map(int, sys.stdin.buffer.readline().split()))
    n = N//(A+B)
    m = N%(A+B)
    print(A*n + min(m, A) if m > A else A*n + m)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <stdio.h>
#define NIL -1
long long Fibonacci(int);



long long A[100];



int main(){
int n,i;
for(i=0;i<100;i++) A[i]=NIL;

scanf("%d",&n);

printf("%lld\n",Fibonacci(n));

return 0;


}

long long Fibonacci(int n){
  if(n==0||n==1) return A[n]=1;
  if(A[n] != NIL) return A[n];
  return A[n]=Fibonacci(n-2)+Fibonacci(n-1);

}



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

int main() {
    
  int N,A,B,C,D;
  cin >> N;
  
  A = N/1000;
  B = (N%1000)/100;
  C = (N%1000)%100/10;
  D = (N%1000)%100%10;
    
  if(A==B&&B==C){
      cout<<"Yes"<<endl;
  }
  else if( B==C&&C==D){
      
   cout<<"Yes"<<endl;
  }
   else{
       cout <<"No"<<endl;
   }
}


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

const ll MAXN = 200000;

ll N, ans=100000000000000, tmp1=0, tmp2=0;
vector<ll> A(MAXN, 0);

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
    ll ng = -3000000005;
    ll ok = 3000000005;
    while(ng+3<=ok) {
        ll mid1 = (2*ng + ok)/3;
        ll mid2 = (ng + 2*ok)/3;
        //cout << ng << " : " << ok << endl;
        //cout << mid1 << " : " << mid2 << endl;
        //cout << endl;
        tmp1 = 0;
        tmp2 = 0;
        for(int i=0;i<N;i++) {
            tmp1 += abs(mid1+i+1-A[i]);
            tmp2 += abs(mid2+i+1-A[i]);
        }
        if(tmp2>tmp1) ok = mid2;
        else ng = mid1;
    }
    for(int i=ng;i<=ok;i++) {
        tmp1 = 0;
        for(int j=0;j<N;j++) {
            tmp1 += abs(i+j+1-A[j]);
        }
        ans = min(ans, tmp1);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int v[3];
    while(cin >> v[0] >> v[1] >> v[2]) {
        sort(v, v+3);
        cout << (v[0] == 5 && v[1] == 5 && v[2] == 7? "YES" : "NO") << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int X, N; cin >> X >> N;
    vector<int> p(N);
    rep(i, N) cin >> p[i];
    sort(ALL(p));
    int i = 0;
    while (true) {
        if (!binary_search(ALL(p), X-i)) {
            cout << X-i << endl;
            return 0;
        }
        if (!binary_search(ALL(p), X+i)) {
            cout << X+i << endl;
            return 0;
        }
        i++;
    }
}


Measured memory_bytes: 3624
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

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

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	s := make([]int, N)
	for i := 0; i < N; i++ {
		s[i] = getInt()
	}
	var dp [101][11001]int
	dp[0][0] = 1
	for i := 1; i <= N; i++ {
		for j := 0; j < 11000; j++ {
			if dp[i-1][j] == 1 {
				dp[i][j] = 1
			}
			if j >= s[i-1] && dp[i-1][j-s[i-1]] == 1 {
				dp[i][j] = 1
			}
		}
	}

	ans := 0
	for i := 11000; i >= 0; i-- {
		if i%10 != 0 && dp[N][i] == 1 {
			ans = i
			break
		}
	}
	out(ans)
}


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

count = [0] * (10 ** 5 + 1)

for a in A:
  count[a] += 1
  
ans = 0  
for i in range(1, 10 ** 5):
  X = count[i-1] + count[i] + count[i+1]
  ans = max(ans, X)
  
print(ans)

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

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)

using namespace std;
using ull = unsigned long long;

const ull MOD = 1000000007;

int main(void)
{
    int N, L[3];
    cin >> N;
    fa(i, L) cin >> i;
    auto l = vc(int, N);
    fa(i, l) cin >> i;
    int ans = 1000000000;
    int sum[4], c[4];
    int j;
    for (int bit = (1 << (2*N)) - 1; bit >= 0; bit--)
    {
        lpn(i, 4) sum[i] = c[i] = 0;
        lpn(i, N)
        {
            j = (bit >> (i*2)) & 3;
            sum[j] += l[i];
            c[j]++;
        }
        if(!c[0] || !c[1] || !c[2]) continue;
        sum[3] = 0;
        lpn(i, 3) sum[3] += abs(L[i] - sum[i]) + 10 * (c[i] - 1);
        ans = min(ans, sum[3]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int N,M,x,y,visited[100010] = {},visited2[100010] = {};
ll dp[100010] = {},ans[100010] = {};
vector<vector<int>> v(100010); 

void dfs(int n){
	visited[n] = 1;
	dp[n] = 1;
	for(auto x:v[n]){
		if(visited[x]==0){
			dfs(x);
			(dp[n] *= 1+dp[x])%=M;
		}
	}
}

void dfs2(int n,int m,ll value){
	visited2[n] = 1;
	vector<ll> left,right;
	for(auto x:v[n]){
		if(x==m){
			left.push_back((1+value)%M);
			right.push_back((1+value)%M);	
		}else{
			left.push_back((1+dp[x])%M);
			right.push_back((1+dp[x])%M);
		}
	}
	int s = v[n].size();
	for(int i=1;i<s;i++) (left[i] *= left[i-1])%=M;
	for(int i=s-2;i>=0;i--) (right[i] *= right[i+1])%=M;
	ans[n] = right[0]%M;
	for(int i=0;i<s;i++){
		int x = v[n][i];
		if(visited2[x]==0){
			ll res = 1;
			if(i!=0) (res *= left[i-1])%=M;
			if(i!=s-1) (res *= right[i+1])%=M;
			dfs2(x,n,res);
		}
	}
}

int main(){
	cin >> N >> M;
	if(N==1){
		cout << 1 << endl;
		return 0;
	}
	for(int i=0;i<N-1;i++){
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1); dfs2(1,0,0);
	for(int i=1;i<=N;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 25088
// jimjam
#include <cstdio>
using ll = long long;

ll a,b,c,t;

int main() {
    scanf("%lld %lld %lld", &a, &b, &c);
    t = a+b+c;
    if (a%2 == 0 && b%2 == 0 && c%2 == 0 && a==b && a == c) {
        printf("-1\n");
        return 0;
    }

    ll ans = 0;
    while (a%2 == 0 && b%2 == 0 && c%2 == 0) {
        a = (t-a)/2;
        b = (t-b)/2;
        c = (t-c)/2;
        ans++;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 888
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
ll a,b,c,k;
int main()
{
    scanf("%lld %lld %lld",&a,&b,&c);
    if(b>=a)
    {
        printf("1\n");
        exit(0);
    }
    if(c>=b)
    {
        printf("-1\n");
        exit(0);
    }
    if((a-b)%(b-c)>=1)
		k=1;
    printf("%lld\n",((a-b)/(b-c)+k)*2+1);
}

Measured memory_bytes: 128
n, m = map(int, input().split())
listS= list(input())
listT = list(input())


def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


l = n*m // gcd(n, m)
a = l//n
b = l//m

if listS[0]!=listT[0]:
    print(-1)
else:
    checkI = a*b // gcd(a, b)
    if checkI > l:
        print(l)
    else:
        index=0
        flag=0
        while index < l//min(a, b):
            if index*checkI//a > len(listS)-1 or index*checkI//b > len(listT)-1:
                break
            elif listS[index*checkI//a] != listT[index*checkI//b]:
                print(-1)
                flag=1
                break
            else:
                index+=1
        if flag==0:
            print(l)

Measured memory_bytes: 4628
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vll a(n);
    REP(i,n) cin >> a[i];
    sort(rALL(a));
    ll ans = 0;
    {
        ll t = 0;
        if(n%2==0){
            ll n2 = n/2;
            REP(i,n2-1){
                t += 2*a[i];
            }
            t += a[n2-1];
            t -= a[n2];
            REP(i,n2-1){
                t -= a[n2+1+i] * 2;
            }
            ans = max(t,ans);
        }else{
            ll n2 = n/2;
            REP(i,n2-1){
                t += 2*a[i];
            }
            t += a[n2-1];
            t += a[n2];
            REP(i,n2){
                t -= a[n2+1+i] * 2;
            }
            ans = max(t,ans);
        }
    }
    {
        ll t = 0;
        if(n%2==0){
            ll n2 = n/2;
            REP(i,n2-1){
                t += 2*a[i];
            }
            t += a[n2-1];
            t -= a[n2];
            REP(i,n2-1){
                t -= a[n2+1+i] * 2;
            }
            ans = max(t,ans);
        }else{
            ll n2 = n/2;
            REP(i,n2){
                t += 2*a[i];
            }
            t -= a[n2];
            t -= a[n2+1];
            REP(i,n2-1){
                t -= a[n2+2+i] * 2;
            }
            ans = max(t,ans);
        }
    }
    cout << ans <<  endl;
    return 0;
}

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

int main(){
   ll a,b,c,d;
   cin>>a>>b;
   bool flag=false;
   for(int i=1;i<=1000;i++){
       c=i*0.08;
       d=i*0.1;
       if(c==a && d==b)
         {cout<<i;flag=true; break;}
   }
   
   if(flag==false)
    cout<<-1;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	long double a,b,c;
	cin>>a>>b>>c;
	if(((c*c)+(a*a)+(b*b)-(2*a*b)-(2*c*(a+b)))>0&&c-a-b>0)
	cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

int main() {
  int x;
  int y=0;
  cin >> x;

  if (x%2 == 0) {
    cout << x/2 -1 << endl;
    return 0;
  }
  else {
    cout << x/2 << endl;
    return 0;
  }


}


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

int main() {
	int nums[5];
	for (int i = 0; i < 5; i++) {
		cin >> nums[i];
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4 - i; j++) {
			if (nums[j] < nums[j + 1]) {
				swap(nums[j], nums[j + 1]);
			}
		}
	}
	for (int i = 0; i < 4; i++) {
		cout << nums[i] <<' ';
	}
	cout << nums[4] << endl;
	return 0;
}

Measured memory_bytes: 3068
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

struct P {
    i64 sum;
    int i, j, k;
    bool operator< (const P &o) const { return sum < o.sum; }
    bool operator> (const P &o) const { return sum > o.sum; }
};

i64 hash(i64 a, i64 b, i64 c) { return 1'000'001 * a + 1'001 * b + c; }

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

    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    vector<i64> a(X), b(Y), c(Z);

    for (int i = 0; i < X; ++i) cin >> a[i];
    for (int i = 0; i < Y; ++i) cin >> b[i];
    for (int i = 0; i < Z; ++i) cin >> c[i];
    sort(ALL(a), greater<>());
    sort(ALL(b), greater<>());
    sort(ALL(c), greater<>());


    unordered_set<i64> used;
    priority_queue<P> pq;
    pq.push({a[0] + b[0] + c[0], 0, 0, 0});
    used.emplace(0);

    while(K--) {
        const auto p = pq.top(); pq.pop();
        const int i = p.i;
        const int j = p.j;
        const int k = p.k;
        cout << p.sum << endl;

        {
            const int i = p.i + 1;
            const i64 h = ::hash(i, j, k);
            if (i < X && !used.count(h)) {
                used.emplace(h);
                pq.push({a[i] + b[j] + c[k], i, j, k});
            }
        }
        {
            const int j = p.j + 1;
            const i64 h = ::hash(i, j, k);
            if (j < Y && !used.count(h)) {
                used.emplace(h);
                pq.push({a[i] + b[j] + c[k], i, j, k});
            }
        }
        {
            const int k = p.k + 1;
            const i64 h = ::hash(i, j, k);
            if (k < Z && !used.count(h)) {
                used.emplace(h);
                pq.push({a[i] + b[j] + c[k], i, j, k});
            }
        }
    }

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N,M;
    cin >> N >> M;

    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}

Measured memory_bytes: 256
import java.math.BigDecimal
import java.util.*

fun main(arr:Array<String>) {
    val numCount = readLine()!!.toInt()
    val numList = (1..numCount).map { readLine()!!.toLong() }.distinct()

    var num = numList[0]
    for(i in numList.indices) {
        num = getKoubai(num, numList[i])
    }
    println(num)
}

fun getKoubai(num1:Long, num2:Long):Long {
    val kouyaku = getKouyaku(num1, num2)
    val ret = (num1/kouyaku)*(num2/kouyaku)*kouyaku
    return ret
}

fun getKouyaku(num1:Long, num2:Long):Long {
    if(num1 % num2 == 0L) {
        return num2
    }
    return getKouyaku(num2, num1%num2)
}


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

#define MAXN 100005
#define lowbit(x) x & -x

using namespace std;

int n, N;
int a[MAXN][4], b[MAXN], c[MAXN], t[2][MAXN * 3], sum[2];

int read() {
    char c = getchar();
    int x = 0;
    while (!isdigit(c))
        c = getchar();
    while (isdigit(c)) {
        x = (x << 3) + (x << 1) + c - '0';
        c = getchar();
    }
    return x;
}

void add(int c, int x, int v) {
    while (x <= N) {
        t[c][x] += v;
        x += lowbit(x);
    }
}

int query(int c,int x) {
    int res = 0;
    while (x) {
        res += t[c][x];
        x -= lowbit(x);
    }
    return res;
}

int main() {
    n = read();
    N = n * 3;
    for (int j = 1; j <= 3; ++j)
        for (int i = 1; i <= n; ++i)
            a[i][j] = read();
    for (int i = 1; i <= n; ++i) {
        if (a[i][1] > a[i][2]) {
            sum[i & 1] ^= 1;
            swap(a[i][1], a[i][3]);
        }
        b[i] = a[i][3];
        if (a[i][1] != a[i][2] - 1 || a[i][2] != a[i][3] - 1 || b[i] % 3 != 0 || ((b[i] / 3) & 1) != (i & 1)) {
            puts("No");
            return 0;
        }
    }
    for (int i = n; i >= 1; --i) {
        sum[(i & 1) ^ 1] ^= query(i & 1, b[i] / 3) & 1;
        add(i & 1, b[i] / 3, 1);
    }
    if ((sum[0] & 1) || (sum[1] & 1))
        puts("No");
    else
        puts("Yes");
}


Measured memory_bytes: 3712
from random import shuffle

N,M = map(int,input().split())

E = [list() for _ in range(N)]
for _ in range(M):
    a,b = map(int,input().split())
    E[a-1].append(b-1)

# find cycle
def cycle(E, visited):
    path_set = [False]*N
    path = []
    def dfs(v):
        if path_set[v]:
            path.append(v)
            return True
        if visited[v]:
            return False
        visited[v] = True
        path.append(v)
        path_set[v] = True
        for u in E[v]:
            if dfs(u):
                return True
        path.pop()
        path_set[v] = False
        return False

    while True:
        try:
            v = visited.index(False)
            if dfs(v):
                return path[path.index(path[-1]):-1]
        except ValueError:
            return None

c = cycle(E, [False]*N)
if c is None:
    print(-1)
    exit()

while True:
    c_set = set(c)
    cnt = 0
    for u in c:
        E[u] = [v for v in E[u] if v in c_set]
        shuffle(E[u])
        cnt += len(E[u])
    if cnt == len(c):
        break
    else:
        visited = [True]*N
        for v in c:
            visited[v] = False
        c = cycle(E,visited)

print(len(c))
for u in c:
    print(u+1)

Measured memory_bytes: 43756
data_num=int(input())
data=input().split()

rdata_num=int(input())
for i in range(rdata_num):
  dict={}
  for i in range(data_num):
    dict[i]=int(data[i])

  list=[]
  p,x=input().split()   
  dict[int(p)-1]=int(x)
  
  for dict_val in dict.values():
    list.append(dict_val)

  print(sum(list))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int D = Integer.parseInt(line);
		int[] c = new int[26];//26
		int[][] s = new int[D][26];//26
//		int[] t = new int[D];
		int[] last = new int[26];

		line = sc.nextLine();
		String[] lines = line.split(" ");
		for(int i = 0; i < lines.length; i++) {
			c[i] = Integer.parseInt(lines[i]);
		}

		for(int i = 0; i < D; i++) {
			line = sc.nextLine();
			lines = line.split(" ");
			for(int j = 0; j < 26; j++) {
				s[i][j] = Integer.parseInt(lines[j]);
			}
		}

//		for(int i = 0; i < D; i++) {
//			for(int j = 0; j < 26; j++) {
//				System.out.print(s[i][j] + " ");
//			}
//			System.out.println();
//		}

		long sum = 0;
//		long answer = 0;
		for(int i = 0; i < D; i++) {
			sum = 0;
			long max = -1;
			int temp = 0;
			for(int j = 0; j < 26; j++) {
				sum = sum + c[j];
				if(s[i][j] > max) {
					max = s[i][j];
					temp = j;
				}
			}
			last[temp] = i+1;
			System.out.println(temp+1);

//			for(int j = 0; j < 26; j++) {
//				sum = sum + c[j]*( (i+1) - last[j] );
//			}
//			answer = answer + s[i][t[i]] - sum;
//			System.out.println(answer);
		}
	}

}


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

int cnt=0;
void merge_sort(vector<int> &a) {
    int n = a.size();
    if (n==1) return;

    vector<int> b(begin(a), begin(a) + n/2);
    vector<int> c(begin(a) + n/2, end(a));
    merge_sort(b);
    merge_sort(c);

    for (int i = 0, j = 0, k = 0; i < n; ++i) {
        if (k == c.size())      a[i] = b[j++];
        else if (j == b.size()) a[i] = c[k++];
        else if (b[j] < c[k])   a[i] = b[j++];
        else                    a[i] = c[k++];
        cnt++;
    }
}
signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    merge_sort(a);
    for (int i = 0; i < n; ++i) {
        cout << a[i];
        cout << (i != n -1 ? " " : "\n");
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 8716
/**
 *    Author:  "Robin Singh" !!!!    
**/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define mp make_pair
#define str string 
#define szz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)     // 0 -> n-1 (i,0,n)
#define bk(i, j, k) for(int i = j-1; i >= k; i--)  // n-1 -> 0 (i,n,0)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0 //
#define rtn return 
#define itt(a)   __typeof((a).begin())
#define RT  (cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n")  // Run Time
#define nl "\n"  // New Line
#define dbg(x) (cerr << #x << " = " << x << "  ")
#define enl (cerr << "\n")
#define dbgg(x,y) (cerr << #x << " = " << x << " -> " << #y << " = " << y << "\n")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int,int> > vpii;
typedef vector< pair<ll, ll> > vpll;
const long long mod = 1e9+7;
const ld eps = 1e-9;
const int inf = (1<<30);
const ll INF = (1LL<<61);

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }
ll expo(ll x, ll y){ ll res = 1; x = x % mod;  while (y > 0) { if (y & 1)res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll n, ans = 0;
    cin >> n;
    ll a[n+1];
    for(int i=1; i<=n; i++){
        cin >> a[i];
        a[i] -= i;
    }
    // min deviation
    // mean is not the answer, median is the answer
    sort(a+1, a+n+1);
    ll b;
    if(n & 1) b = a[n/2 + 1];
    else b = (a[n/2] + a[n/2 + 1])/2;
    for(int i=1; i<=n; i++)
        ans += abs(a[i]-b);
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	private static Scanner sc;

	public static void main(String[] args) throws Exception {
		sc = new Scanner(System.in);
		String[] S = sc.nextLine().split("");

		// ACGTのいずれかがでてきたら、ACGT以外がでてくるまでカウント
		// カウントマックスに代入して、それ以降同じように繰り返す。
		int i = 0;
		int max = 0;
		for (String str : S) {
			if (str.equals("A") || str.equals("G") || str.equals("C") || str.equals("T")) {
				i++;
				max = Math.max(i, max);
			} else {
				i = 0;
			}
		}

		System.out.println(max);

	}
}


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

long answer(list<int> l) {
    long ans = 0;

    int before = -1;
    for(auto itr = l.begin(); itr != l.end(); ++itr) {
        if (before == -1) {
            before = *itr;
            continue;
        }

        ans += abs(*itr - before);
        before = *itr;
    }

    return ans;
}

int main() {
    int n;
    cin >> n;

    int a[n];
    list<int> la;

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

    sort(a, a + n);

    int idx_min, idx_max;
    int dfront, dback;

    // 最大値を中央に置き、最小値を最大値の左右に置いてから、並べ替えを行うパターン
    la.push_back(a[n - 1]);

    idx_min = 0;
    idx_max = n - 2;

    bool place_min_num = true;
    while (idx_min <= idx_max) {
        if (place_min_num) {
            la.push_front(a[idx_min++]);

            if (idx_min > idx_max) {
                break;
            }

            la.push_back(a[idx_min++]);
        } else {
            la.push_front(a[idx_max--]);

            if (idx_min > idx_max) {
                break;
            }

            la.push_back(a[idx_max--]);
        }

        place_min_num = !place_min_num;
    }

    long ansA = answer(la);

    // 最小値を中央に置き、最大値を最小値の左右に置いてから、並べ替えを行うパターン
    la.clear();
    la.push_back(a[0]);

    idx_min = 1;
    idx_max = n - 1;

    place_min_num = false;
    while (idx_min <= idx_max) {
        if (place_min_num) {
            la.push_front(a[idx_min++]);

            if (idx_min > idx_max) {
                break;
            }

            la.push_back(a[idx_min++]);
        } else {
            la.push_front(a[idx_max--]);

            if (idx_min > idx_max) {
                break;
            }

            la.push_back(a[idx_max--]);
        }

        place_min_num = !place_min_num;
    }

    long ansB = answer(la);

    std::cout << std::max(ansA, ansB) << endl;

    return 0;
}


Measured memory_bytes: 6912
#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 VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define OUT(x) cout << x << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

ll gcd(ll x, ll y){
  if(y == 0) return x;
  return gcd(y,x%y);
}

ll lcm( ll m, ll n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm

int main(){
  int n;
  cin >> n;
  ll t;
  ll LCM;

  cin >> LCM;
  for(int i=1;i<n;++i){
    cin >> t;
    LCM = lcm(LCM,t);
  }
  cout << LCM << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#define MOD 1000000007
using namespace std;
const int MAXN = 1000005;
int n,m,k,fac[MAXN],inv[MAXN];
typedef long long ll;
inline int ksm(int x,int k)
{
	int ret=1;
	while(k){
		if(k&1)ret=(ll)ret*x%MOD;
		x=(ll)x*x%MOD;
		k>>=1;
	}
	return ret;
}
int ter[MAXN];
inline void init(int n)
{
	fac[0]=1;
	ter[0]=1;
	for(int i=1;i<=n;++i)ter[i]=(ll)ter[i-1]*3%MOD;
	for(int i=1;i<=n;++i)fac[i]=(ll)fac[i-1]*i%MOD;
	inv[n]=ksm(fac[n],MOD-2);
	for(int i=n-1;i>=0;--i)
		inv[i]=(ll)inv[i+1]*(i+1)%MOD;
}
inline int C(int n,int m)
{
	return n>m?0:(ll)fac[m]*inv[m-n]%MOD*inv[n]%MOD;
}
inline void add(int &x,int a)
{
	x+=a;
	if(x>=MOD)x-=MOD;
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	init(n+m+k);
	int ans=0,now=1;
	if(m>k)swap(m,k);
	for(int i=0;i<=m+k;++i){
		add(ans,(ll)C(n-1,i+n-1)*ter[m+k-i]%MOD*now%MOD);
		if(i<m)now=(ll)now*2%MOD;
		else if(i>=m && i<k)now=((ll)now*2%MOD-C(m,i)+MOD)%MOD;
		else now=(((ll)now*2%MOD-C(i-k,i)+MOD)%MOD-C(m,i)+MOD)%MOD;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 11520