akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
    int N;
    string S;
    cin >> N >> S;

    vector<int> east(N);
    if(S.front() == 'E') {
        east[0] = 1;
    }
    for(int i=1; i<N; i++) {
        if(S[i] == 'E') {
            east[i] = east[i-1] + 1;
        } else {
            east[i] = east[i-1];
        }
    }

    int ans = east[N-1] - east[0];
    for(int leader=1; leader<N-1; leader++) {
        int ans_tmp = (leader - east[leader-1]) + (east[N-1] - east[leader]);
        ans = min(ans, ans_tmp);
    }
    ans = min(ans, N-1 - east[N-2]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1796
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;

int main() {
	int n;
	cin >> n;
	cout << 800 * n - 200 * (n / 15) << endl;
}

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

int h, w;

char maze[51][51];
int bm[51][51];
int wm[51][51];

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

void dfsB(int y, int x){
	for(int i = 0; i < 4; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(0 <= nx and nx < w and 0 <= ny and ny < h and bm[ny][nx] == 0 and maze[ny][nx] == '.'){
			bm[ny][nx] = 1;
			dfsB(ny, nx);
		}
	}
	return;
}

void dfsW(int y, int x){
	for(int i = 0; i < 4; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(0 <= nx and nx < w and 0 <= ny and ny < h and wm[ny][nx] == 0 and maze[ny][nx] == '.'){
			wm[ny][nx] = 1;
			dfsW(ny, nx);
		}
	}
	return;
}


int main(){
while(1){//start

	//init
	for(int i = 0; i < 50; i++){
		for(int j = 0; j < 50; j++){
			maze[i][j] = 'a';
			bm[i][j] = 0;
			wm[i][j] = 0;
		}
	}



	//int w, h;
	cin >> w >> h;
	if(w == 0 and h == 0) break;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++) cin >> maze[i][j];
	}

	//debug
	/*
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++) cout << maze[i][j] << " ";
		cout << endl;
	}
*/
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(maze[i][j] == 'W') dfsW(i, j);
			if(maze[i][j] == 'B') dfsB(i, j);
		}
	}

/*
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(maze[i][j] == 'B'){
				if(i - 1 >= 0) wm[i - 1][j] = 0;
				if(i + 1 < 50) wm[i + 1][j] = 0;
				if(j - 1 >= 0) wm[i][j - 1] = 0;
				if(j + 1 < 50) wm[i][j + 1] = 0;
			}
			if(maze[i][j] == 'W'){
				if(i - 1 >= 0) bm[i - 1][j] = 0;
				if(i + 1 < 50) bm[i + 1][j] = 0;
				if(j - 1 >= 0) bm[i][j - 1] = 0;
				if(j + 1 < 50) bm[i][j + 1] = 0;
			}
		}
	}
*/
	int ansb = 0;
	int answ = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(wm[i][j] == 0 and bm[i][j] == 1) ansb += 1;
			if(bm[i][j] == 0 and wm[i][j] == 1) answ += 1;
		}
	}

	/*
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			ansb += bm[i][j];
			answ += wm[i][j];
		}
	}
*/
	cout << ansb << " " << answ << endl;
}//end
	return 0;
}



Measured memory_bytes: 3152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ab = br.readLine().split(" ");
        int a = Integer.parseInt(ab[0]);
        int b = Integer.parseInt(ab[1]);
        System.out.println(problem137a(a, b));
    }

    private static int problem137a(int a, int b) {
        return Math.max(Math.max((a + b), (a - b)), (a * b));
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
 
template < typename T > using index_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;
int main() 
{

  fast();

  	 str s;
  	 cin>>s;
  	 ll a=753,mi=1111111;
  	 f(i,0,s.size()-2)
  	 {
  	 	str s1="";
  	 	f(j,i,i+3)
  	 	{
  	 		s1+=s[j];

  	 	}
  	 	ll a1=(s1[0]-'0')*100+(s1[1]-'0')*10+s1[2]-'0';
  	 	// cout<<a1<<edl;
  	 	mi=min(mi,abs(a1-a));
  	 }
  	 cout<<mi;


    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
char w[11] = "akstnhmyrw";
char x[11] = "1234567890";
char y[6] = "aiueo";
char z[6] = "TLURD";
string S;
int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i += 2) {
		string T = S.substr(i, 2);
		int a, b;
		for (int j = 0; j < 10; j++) {
			if (x[j] == T[0]) { a = j; }
		}
		for (int j = 0; j < 5; j++) {
			if (z[j] == T[1]) { b = j; }
		}
		if (a == 9 && b == 2) { cout << "nn"; }
		else if (a == 0) { cout << y[b]; }
		else { cout << w[a] << y[b]; }
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1184
N, K = map(int, input().split())
S = list(input())

if S[K - 1] == 'A':
    S[K - 1] = 'a'
elif S[K - 1] == 'B':
    S[K - 1] = 'b'
else:
    S[K - 1] = 'c'

ans = ''.join(S)
print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

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

    int index;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        if (a == 1) index = i;
    }

    cout << (n-1 + k - 2) / (k-1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  int score = 0;
  for (int i = 1; i < s.size(); i++) {
    if (s[i - 1] == s[i]) score++;
  }

  int ans = min(score + 2 * k, n - 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>

using namespace std;

int main() {
	int D, N, X;
	cin >> D >> N;

	if (N == 100)N++;
	X = pow(100, D);
	cout << X * N << endl;

	return 0;
}

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


#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;


using namespace std;

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

    double h, a;
    cin >> h >> a;
    cout << ceil(h/a);
    return 0;
}


Measured memory_bytes: 3728
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
import java.util.HashMap;

public class Main
{
  static HashMap<String, Long> DP[];
  static String Chars = "ACGT";
  
  static boolean isValid(String S)
  {
    if (S.contains("AGC"))
    {
      return false;
    }
    for (int i = 1; i < S.length(); i++)
    {
      String temp = "";
      for (int j = 0; j < i - 1; j++)
      {
        temp += S.charAt(j);
      }
      temp += S.charAt(i) + "" + S.charAt(i - 1);
      for (int j = i + 1; j < S.length(); j++)
      {
        temp += S.charAt(j);
      }
      if (temp.contains("AGC"))
      {
        return false;
      }
    }
    return true;
  }
  
  static long DFS(int N, String cur)
  {
    if (DP[N].containsKey(cur))
    {
      return DP[N].get(cur);
    }
    if (N == 0) return 1;
    DP[N].put(cur, 0l);
    for (int i = 0; i < Chars.length(); i++)
    {
      if (isValid(cur + Chars.charAt(i)))
      {
        long prev = DP[N].get(cur);
        long result = DFS(N - 1, cur.substring(1) + Chars.charAt(i));
        int MOD = (int)1e9 + 7;
        DP[N].put(cur, (prev + result) % MOD);
      }
    }
    return DP[N].get(cur);
  }
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(); DP = new HashMap[N + 1];
    for (int i = 0; i <= N; i++)
    {
      DP[i] = new HashMap<>();
    }
    long result = DFS(N, "TTT");
    System.out.println(result);
  
  }
}


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

int main() {
  char S[10];
  cin >> S;
  
  int ACGT[strlen(S)+1] = {0};
  
  int max = 0, count = 0;
  
  for (int i = 0; i < strlen(S); ++i) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      count++;
    } else {
      if (!count) { 
        continue; 
      } else { 
        ACGT[i] = count;
        count = 0;
      }
    }
  }
  
  ACGT[strlen(S)] = count;
  
  for (int i = 0; i <= strlen(S); ++i) {
    if (max < ACGT[i]) {
      max = ACGT[i];
    }
  }
  
  cout << max << endl;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    
    int left = 1, right = n;
    rep(i, m) {
        int l, r;
        cin >> l >> r;
        left = max(l, left);
        right = min(right, r);
    }
    
    if (right - left >= 0)
        cout << right-left+1 << endl;
    else
        cout << 0 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void){

    char tmp =0;
    int num1,num2,answer =0;
    
    scanf("%d%d", &num1, &num2);
    
    while(answer == 0){
        if(num2==num1)
        {
            answer = num1;
        }
        else if (num2>num1)
        {
            num2=num2%num1;
            if(num2==0)
            {
                answer = num1;
            }
        }
        else
        {
            num1=num1%num2;
            if(num1==0)
            {
                answer = num2;
            }
        }
    }
    printf("%d\n",answer);
    
    return 0;
}



Measured memory_bytes: 2076
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    int c = 0,flag = 0;
    int a,b;
    for(int i=0;i<t;i++){
        cin>>a>>b;
        if(a == b){
            c++;
        }
        else if(a!=b){
            if(c >= 3){
                cout<<"Yes";
                flag = 1;
                break;
            }
            else{
                c = 0;
            }
        }
    }
    if(flag == 0){
        if(c >= 3){
        cout<<"Yes";
      }
      else cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3652
/*
 * Pawan Harendra Mishra
 */

#include <bits/stdc++.h>
using namespace std;

#define X first
#define Y second
typedef long long ll;
typedef pair<ll,ll> pll;

int x;
vector<int> a = {100, 101, 102, 103, 104, 105};
vector<int> b(100001, -1);

bool reduce(int c) {
    if (c == 0) return true;
    else if (c < 0) return false;

    if (b[c]==0) return false;
    else if (b[c]==1) return true;
    
    bool ans = false;
    for (ll i=0; i<a.size(); i++) {
        if (c - a[i] >= 0) b[c-a[i]] = reduce(c - a[i]);
        ans = ans || reduce(c - a[i]);
    }
    
    b[c] == ans;
    return ans;
}

int main(int argc, char const *argv[])
{
    //ios::sync_with_stdio(false);
    //cin.tie(NULL);
    
    cin >> x;
    if (reduce(x)) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

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

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

int ans;
int n, k;
void f(int sum, int cnt) {

    if (cnt == n) {
        ans = sum;
        return;
    }
    if (sum*2 > sum+k)
        f(sum+k, cnt+1);
    else
        f(sum*2, cnt+1);


}

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

    cin >> n >> k;
    f(1, 0);
    cout << ans << endl;

    return 0;
 }


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <cmath>

using namespace std;

#define FAST_IO() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define USE_DB() cout << fixed; cout.precision(10);

#define pqu priority_queue
#define que queue
#define stk stack
#define vec vector

typedef long long ll;
typedef double db;
typedef string str;

#define in(x) cin >> x
#define ini(x) int x; cin >> x
#define inl(x) ll x; cin >> x
#define ins(x) str x; cin >> x

#define out(x) cout << x
#define outb(x) cout << x << ' '
#define outn(x) cout << x << '\n'

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define forn(i, s, e) for (int i = s; i < e; i++)
#define forr(i, s, e) for (int i = s; i >= e; i--)
#define ford(i, s, e, d) for (int i = s; i < e; i += d)
#define fors(i, n) for (int i = 1; i*i <= n; i++)

int main() {
	FAST_IO();

    ins(s);
    inl(k);
    int pos = -1;
    forn(i, 0, sz(s)) {
        if (s[i] != '1') break;
        pos = i;
    }
    if (pos == -1) {
        outn(s[0]);
        return 0;
    } else {
        if (pos+1 >= k) {
            outn(1);
            return 0;
        } else {
            outn(s[pos+1]);
            return 0;
        }
    }

	return 0;
}


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

int main(){
  float n, d;
  cin >> n >> d;
  float guardedArea = (d + d) + 1.0;
  cout << ceil(n / guardedArea) << endl;
}

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

int main()
{
  int rating, kyu;

  cin >> rating;
  if(rating >= 400 && rating <= 599)
  {
    kyu = 8;
  }

  if(rating >= 600 && rating <= 799)
  {
    kyu = 7;
  }

  if(rating >= 800 && rating <= 999)
  {
    kyu = 6;
  }

  if(rating >= 1000 && rating <= 1199)
  {
    kyu = 5;
  }

  if(rating >= 1200 && rating <= 1399)
  {
    kyu = 4;
  }

  if(rating >= 1400 && rating <= 1599)
  {
    kyu = 3;
  }

  if(rating >= 1600 && rating <= 1799)
  {
    kyu = 2;
  }

  if(rating >= 1800 && rating <= 1999)
  {
    kyu = 1;
  }

  cout << kyu << endl;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  if(a == b) cout << "Draw" << endl;
  else if(a == 1 || (a > b && b != 1)) cout << "Alice" << endl;
  else if(b == 1 || (a < b && a != 1)) cout << "Bob" << endl;
  return 0; 
}


Measured memory_bytes: 256
a, b, c= map(int, input().split())
ans = 0
def calc(a, b):
    if a < b:
        r = b-a
        if r % 2:
            return r//2 + 2
        return r//2
    else:
        return a-b
def solve(a, b, c):
    return calc(a, c) + calc(b, c)
print(min(solve(a, b, c), solve(b, c, a), solve(c, a, b)))


Measured memory_bytes: 38384
import sys

str_S=input()
S=int(str_S)
if not(S >= 0 and S <=86400):
    sys.exit()
h=S // 3600
m=(S % 3600) // 60
s=(S % 3600) % 60
print(str(h) + ":" + str(m) + ":" + str(s))


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

using namespace std;

char S[202020];
int D[202020][3];
int n;

int main()
{
	int i;
	
	scanf("%s", S);
	
	n = strlen(S);
	
	D[0][0] = 1; D[0][1] = -1e9; D[0][2] = -1e9;
	D[1][0] = -1e9; D[1][1] = 1; D[1][2] = -1e9;
	D[2][0] = -1e9; D[2][1] = -1e9; D[2][2] = 1;
	
	for(i=3; i<n; i++){
		D[i][0] = -1e9; D[i][1] = -1e9; D[i][2] = -1e9;
	}
	
	for(i=0; i<n; i++){
		{
			D[i][0] = max(D[i][0], max(D[i - 1][1], D[i - 1][2]) + 1);
			if(i > 0 && S[i] != S[i - 1]){
				D[i][0] = max(D[i][0], D[i - 1][0] + 1);
			}
		}
		if(i > 0){
			D[i][1] = max(D[i][1], max(D[i - 2][0], D[i - 2][2]) + 1);
			if(i > 2 && (S[i] != S[i - 2] || S[i - 1] != S[i - 3])){
				D[i][1] = max(D[i][1], D[i - 2][1] + 1);
			}
		}
		if(i > 1){
			D[i][2] = max(D[i][2], max(D[i - 3][0], D[i - 3][1]) + 1);
			if(i > 4 && (S[i] != S[i - 3] || S[i - 1] != S[i - 4] || S[i - 2] != S[i - 5])){
				D[i][2] = max(D[i][2], D[i - 3][2] + 1);
			}
		}
	}
	
	i --;
	
	printf("%d\n", max({D[i][0], D[i][1], D[i][2]}));
	
	return 0;
}

Measured memory_bytes: 2816
#include<stdio.h>

int c[10005],d[10005];

int main(){
	
/*	freopen("10.in","r",stdin);
	freopen("10.out","w",stdout);*/
	int n,i,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&d[i]);
	for(i=1;i<=n;i++)
		scanf("%d",&c[i]);
	for(i=1;i<=n;i++)
		if(d[i]>c[i])ans+=d[i]-c[i];
	printf("%d",ans);
	return 0;
}
	
		
		
 

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int mod = 1e9+7;
const int maxn = 2e5+10;

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

int to[maxn<<1],net[maxn<<1],h[maxn],e=1;
inline void add(int x,int y){
	to[++e]=y;net[e]=h[x];h[x]=e;
}

int fpm(int x,int y){
	int sum=1;
	while(y){
		if(y&1)sum=1ll*sum*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return sum;
}

int k,m,n;
int fa[maxn],ans1[maxn],ans[maxn],siz[maxn];
int fac[maxn],inv[maxn];
int C(int x,int y) {
	return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}
void dfs(int x){
	ans1[x]=siz[x]=1;
	for(register int i=h[x];i;i=net[i]){
		int y=to[i];
		if(y==fa[x])continue;
		fa[y]=x;
		dfs(y);
		siz[x]+=siz[y];
		ans1[x]=1ll*ans1[x]*ans1[y]%mod*C(siz[x]-1,siz[y])%mod;
	}
	//cout<<x<<" "<<ans[x]<<endl;
	return;
}

void dfs2(int x,int Fa){	
	ans[x]=ans1[x];
	int w=1ll*Fa%mod*C(n-1,n-siz[x])%mod;
	//cout<<x<<" "<<Fa<<" "<<w<<endl;
	for(register int i=h[x];i;i=net[i]){
		int y=to[i];
		if(y==fa[x])continue;
		int W=1ll*w*ans1[x]%mod*fpm(ans1[y],mod-2)%mod*fpm(C(n-1,siz[y]),mod-2)%mod;
		dfs2(y,W);
	}
	ans[x]=1ll*ans[x]*w%mod;
	/*int y=fa[x];
	if(y){
		int w=1ll*ans[y]*fpm(ans[x],mod-2)%mod*fpm(C(siz[y]-1,siz[x]),mod-2)%mod;
		cout<<y<<" "<<ans[y]<<" "<<w<<endl;
		ans[x]=1ll*ans[x]*w*C(n-1,n-siz[x])%mod;
	}*/
	return;
}

int main(){
	n=read();
	fac[0]=inv[0]=1;
	for(register int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=fpm(fac[n],mod-2);
	for(register int i=n-1;i>=1;i--)inv[i]=1ll*inv[i+1]*(i+1)%mod;
	for(register int i=1;i<n;i++){
		int x=read(),y=read();
		add(x,y);add(y,x);
	}
	dfs(1);
	dfs2(1,1);
	for(register int i=1;i<=n;i++)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 10880
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int H = sc.nextInt();
		int M = sc.nextInt();
		sc.close();

		// Aの回った角度
		double turnA = ((H * 60) + M) * 0.5;
		// Bの回った角度
		double turnB = M * 6.0;
		// AとBの角度差
		double d = Math.abs(turnA - turnB);

		// 余弦定理で解く
		double X = Math.pow(A, 2) + Math.pow(B, 2) - (2 * A * B * Math.cos(Math.toRadians(d)));
		X = Math.sqrt(X);
		System.out.println(X);
	}
}


Measured memory_bytes: 35916
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x = read::<usize>();
    let y = read::<usize>();
    let groups = [-1, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1];
    println!("{}", if groups[x] == groups[y] { "Yes" } else { "No" });
}


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

int n;
std::string s1, s2;
constexpr long long mod = 1000000007;
int main()
{
	std::cin >> n;
	std::cin >> s1 >> s2;

	bool before;
	int start;
	long long ans = 1;
	if (s1[0] == s2[0]) {
		before = true;
		start = 1;
		ans *= 3;
	}
	else {
		before = false;
		start = 2;
		ans *= 3 * 2;
	}

	for (int i = start; i < n; ++i) {
		bool now = s1[i] == s2[i];

		if (before)
			ans = ans * 2 % mod;
		if (!before && !now)
			ans = ans * 3 % mod;

		if (!now)
			++i;
		before = now;
	}

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


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

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

    ll n,d,a;
    cin >> n >> d >> a;
    vector<pair<ll,ll>> p(n);
    rep(i,n){
        cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(),p.end());
    d = d * 2;
    ll total = 0;
    queue<pair<ll,ll>> q;
    ll ans = 0;
    rep(i,n){
        ll x = p[i].first;
        ll h = p[i].second;

        while(q.size() && q.front().first < x){
            total -= q.front().second;
            q.pop();
        }
        h -= total;
        if(h  > 0){
            ll num = (h + a - 1) / a;
            ans += num;
            ll damage = num * a;
            total += damage;
            q.emplace(x + d, damage);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n + 2,0);
    vector<ll> sum;
    int l = 0;
    ll ans = 0;
    for(int i = 1; i < n + 1; i++){
        cin >> a[i];
    }
    for(int i = 1; i < n + 2; i++){
        ans += abs(a[i] - a[i - 1]);
    }
    for(int i = 1; i < n + 1; i++){
        cout << ans + abs(a[i - 1] - a[i + 1]) - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1])) << endl;
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, h, preh;
    cin >> n;
    cin >> preh;
    int ans = 0;
    int now = 0;
    for (int i = 1; i < n; i++) {
        cin >> h;
        if (preh >= h) {
            now++;
        }
        else {
            ans = max(ans, now);
            now = 0;
        }
        preh = h;
    }
    ans = max(ans, now);
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    A = sorted(Counter(A).items(), key=lambda x: x[1])

    result = 0
    for i in range(max(0, len(A) - K)):
        result += A[i][1]

    print(result)


if __name__ == "__main__":
    main()


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

int main() {
    int A,B,C,X;
    cin >> A >> B >> C>> X;
    int ans = 0;
    for(int i=0; i<=A;i++){
        for(int j=0;j<=B;j++){
            for(int k=0 ;k<=C;k++){
                if(X==500*i+100*j+50*k){
                    ans++;
                }
            }
        }
    }
    cout << ans <<endl;
}

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    string s;
    cin >> s;
    vector<string> ans = {"Sunny", "Cloudy", "Rainy"};
    cout << ans[(find(begin(ans), end(ans), s) - begin(ans) + 1) % 3] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    int q;
    ll b_sum = 0;
    cin >> q;

    vector<ll> a_list;
    priority_queue<ll, vector<ll>, less<ll>> left_que;
    priority_queue<ll, vector<ll>, greater<ll>> right_que;
    
    ll sum_a = 0;
    rep(i, 0, q)
    {
        int t;
        cin >> t;

        if (t == 1)
        {
            ll a, b;
            cin >> a >> b;
            b_sum += b;

            ll l, r;

            if (left_que.size() > 0)
            {
                l = left_que.top();
                r = right_que.top();

                if (a < l or r < a)
                    sum_a += min(abs(l - a), abs(r - a));
            }

            left_que.push(a);
            right_que.push(a);
            l = left_que.top();
            r = right_que.top();

            if (l > r)
            {
                left_que.pop();
                right_que.pop();

                left_que.push(r);
                right_que.push(l);
            }
            // cout << sum_a << '*' << a << ' ' << b << ' ' << min(cand1, cand2) << endl;
        }
        else
        {
            ll med_a = left_que.top();
            cout << med_a << ' ' << sum_a + b_sum << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4588
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string S;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> S;
}

bool isKaibun(string s){
    for (int i = 0; i < s.length(); i++)
    {
        if(s[i]==s[s.length()-1-i]) continue;
        else return false;
    }
    return true;    
}

bool isOK(string s){
    int N=s.length();
    string le=s.substr(0,(N-1)/2);
    string ri=s.substr((N+1)/2);
    DBG(le)
    DBG(ri)
    return (isKaibun(s) && isKaibun(le) && isKaibun(ri));
}

int solve(){
    string ans;
    ans = isOK(S) ? "Yes" : "No";
    cout << ans << endl;
    return 0;
}   

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


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

def main():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    max_ = A[0] + K - A[-1]
    for i in range(1, N):
        max_ = max(max_, A[i] - A[i-1])
    print(K - max_)

if __name__ == "__main__":
    main()

Measured memory_bytes: 26060
N = int(input())
A = list(map(int, input().split()))
no_change = abs(A[0])
for i in range(1,N):
    no_change += abs(A[i]-A[i-1])
no_change += abs(A[N-1])

for i in range(N):
    if i == 0:
        before = 0
        after = A[i+1]
    elif i == N-1:
        before = A[i-1]
        after = 0
    else:
        before = A[i-1]
        after = A[i+1]

    if before <= A[i] <= after or \
        after <= A[i] <= before:
        print(no_change)
    else:
        c = no_change - min(abs(A[i]-before),abs(A[i]-after))*2
        print(c)



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

using namespace std;
using ll = long long;

int main() {
    while(true){
        int n;
        cin>>n;
        int m;
        cin>>m;
        if(n==0)break;

        vector<vector<int>> G(n);
        for(int i = 0;i < m;++i) {
            int a,b;
            cin>>a>>b;
            --a;--b;
            G[a].emplace_back(b);
            G[b].emplace_back(a);
        }
        vector<bool> f(n,false);
        queue<int> q;
        for(auto i:G[0])q.emplace(i);
        while(!q.empty()) {
            auto t=q.front();
            q.pop();
            f[t]=true;
            for(auto i:G[t])f[i]=true;
        }
        int ans=0;
        for(int i = 1;i < n;++i) {
            if(f[i])++ans;
        }
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 3180
#include<stdio.h>
int main()
{
int a,gram,i,sum=0;
scanf("%d %d",&a,&gram);
int arr[a];
for(i=0;i<a;i++)
{
scanf("%d",&arr[i]);
sum+=arr[i];
}
int baki=gram-sum;
int min=arr[0];
for(i=0;i<a;i++)
{
if(arr[i]<min)
{
min = arr[i];
}
}
int z=baki/min;
int k=z+a;

printf("%d",k);

}


Measured memory_bytes: 1712
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

n = ni()
d,x = na()
a = []
for i in range(n):
    a.append(ni())

s = [1]*n
for i in range(n):
    for j in range(1,101):
        if a[i]*j + 1 <= d:
            s[i] += 1
        else:
            break
print(sum(s) + x)


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  int mincost=1e9;
  for(int i=-100;i<101;i++){
    int X=i;
    int cost=0;
    for(int j=0;j<N;j++){
      int B=X-A.at(j);
      cost+=B*B;
    }
    mincost=min(mincost,cost);
  }
  cout << mincost << endl;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N + 1];
        for (int i = 1; i <= N; ++i) {
            A[i] = sc.nextInt();
        }
        sc.close();

        int[] cnt = new int[110000];
        for (int i = 1; i <= N; ++i) {
            if (A[i] > 0) {
                ++cnt[A[i] - 1];
            }
        }
        for (int i = 1; i <= N; ++i) {
            ++cnt[A[i]];
        }
        for (int i = 1; i <= N; ++i) {
            ++cnt[A[i] + 1];
        }
        int max = -1;
        int x = 0;
        for (int i = 1; i <= N; ++i) {
            if (cnt[A[i]] >= max) {
                max = cnt[A[i]];
                x = A[i];
            }
        }

        int res = x;
        int ans = 0;
        for (int i = 1; i <= N; ++i) {
            if (A[i] == x - 1) {
                ++ans;
            } else if (A[i] == x) {
                ++ans;
            } else if (A[i] == x + 1) {
                ++ans;
            }
        }

        System.out.println(ans);
    }
}


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

int main() {
  int n, l; cin >> n >> l;
  vector<string> s(n);
  for(int i = 0; i < n; i++) cin >> s.at(i);
  
  sort(s.begin(), s.end());
  string ans;
  for(int i = 0; i < n; i++){
    ans += s.at(i);
  }
  
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            String s = in.next();
            if (s.charAt(0) >= 'A' && s.charAt(0) <= 'Z')
            {
                out.println('A');
            } else
            {
                out.println('a');
            }
        }

    }
}



Measured memory_bytes: 26764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;
// mp::cpp_int
// mp::cpp_dec_float_100



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  ll n, m;
  cin >> n >> m;
  vector<ll> h(n);
  rep(i, 0, n) cin >> h[i];
  
  vector<bool> ans(n, true);
  rep(i, 0, m) {
    ll a, b;
    cin >> a >> b;
    a--;  b--;
    if(h[a] > h[b]) ans[b] = false;
    else if(h[a] < h[b]) ans[a] = false;
    else {
      ans[a] = false;
      ans[b] = false;
    }
  }
  
  ll cnt = 0;
  rep(i, 0, n) {
    if(ans[i]) cnt++;
  }
  cout << cnt << "\n";
}

Measured memory_bytes: 3992
data class Point(val x: Int, val y: Int)

operator fun Point.unaryMinus() = Point(-x, -y)
operator fun Point.plus(other: Point) = Point(this.x + other.x, this.y + other.y)
operator fun Point.minus(other: Point) = this + (-other)

fun main(args: Array<String>) {
  val (x1, y1, x2, y2) = readLine()!!.split(" ").map { it.toInt() }
  val p1 = Point(x1, y1) 
  val p2 = Point(x2, y2) 
  val p4 = Point(-(p2 - p1).y, (p2 - p1).x) + p1
  val p3 = (p2 - p1) + p4
  println("${p3.x} ${p3.y} ${p4.x} ${p4.y}")
}


Measured memory_bytes: 37660
/*{{{*/
#include<bits/stdc++.h>

typedef long long ll;

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

#define vl vector<ll>
#define pll pair<ll,ll>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;
/*}}}*/

int main() {
  ll l,r,d;
  cin >> l >> r >> d;
  ll ans = r/d - (l-1)/d;

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N)cin >> A[i];
    sort(all(A));
    auto check = [&](ll X) -> bool{
        ll cnt = 0;
        rep(i,N)cnt += (A[i] + X - 1) / X;
        return cnt-N <= K;
    };
    ll ng = 0;
    ll ok = A[N-1];
    while(ok - ng > 1){
        ll mid = (ok + ng) >> 1;
        if(check(mid))ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}


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

using namespace std;

//137D

int main(){
    
    int N, M;cin >> N >> M;
    int A[N],B[N];
    pair<int, int> J[N];
    
    for (int i = 0; i < N; i++) {
        cin>>A[i]>>B[i];
        J[i].first = A[i];
        J[i].second = B[i];
    }
    
    sort(J, J+N);
    
    
    priority_queue<int> job;
 
    int ans = 0;
    
    int k = 0;
    for (int i = 1; i <= M; i++) {
    
        while (J[k].first == i) {
            job.push(J[k].second);
            k += 1;
            if (k == M) {
                break;
            }
        }
        
        
        if (job.size() != 0)  {
            ans += job.top();
            job.pop();
        }
        
        
        
    }
    
    
    cout << ans << endl;
    
    
}


Measured memory_bytes: 2428
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
  string S, P, R;
  getline(cin, S);
  getline(cin, P);

  bool judge = false;
  for(int i = 0; i < S.size(); i++){
    if(S.size() - i - 1 >= P.size() && S.substr(i, P.size()) == P) judge = true;
    else if(S.size() - i - 1 < P.size()){
      R = S.substr(i + 1, S.size() - i - 1) + S.substr(0, P.size() - S.size() + i + 1);
      if(R.substr(0, P.size()) == P) judge = true;
    }
  }
  if(judge) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3204
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {

	int N, K;
	cin >> N >> K;
	int a = 0; 

	for (int i = 0; N !=0; i++) {
		N = N / K;
		a++;
	}

	cout << a << endl;

	return 0;
}

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

constexpr int N=100;

int main(){
   int n, p[N+1], m[N+1][N+1];
   cin >> n;
   for(int i=1; i<=n; i++){
      cin >> p[i-1] >> p[i];
   }

   for(int i=1; i<=n; i++) m[i][i]=0;
   for(int l=2; l<=n; l++){
      for(int i=1; i<=n-l+1; i++){
         int j=i+l-1;
         m[i][j]=(1<<21);
         for(int k=i; k<=j-1; k++)
            m[i][j]=min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
   }

   cout << m[1][n] << endl;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
using namespace std;
void solve()
{
    //Enter your code here Tanmay:)
    int n;
    cin>>n;
    cout<<n*n<<endl;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-08-29 22:18
# @url:https://atcoder.jp/contests/abc177/tasks/abc177_c
import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    n=int(input())
    a=list(map(int,input().split()))
    prefix=[a[0]]
    mod=10**9+7
    for i in range(1,len(a)):
        temp=prefix[-1]%mod+a[i]%mod
        prefix.append(temp%mod)
    s=0
    for i in range(len(a)-1):
        s=s+a[i]*(prefix[-1]-prefix[i])
        s=s%mod
    print (s)
if __name__ == "__main__":
    main()

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll n,q;
vll G[200005];
bool visited[200005];
ll res[200005];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>q;
  rep(i,n-1){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  rep(i,q){
    ll p,x; cin>>p>>x; p--;
    res[p]+=x;
  }
  queue<pll> que;
  que.emplace(0,res[0]);
  while(!que.empty()){
    auto p=que.front(); que.pop();
    ll v=p.first, r=p.second;
    visited[v]=1;
    for(auto nv: G[v]){
      if(visited[nv]) continue;
      res[nv]+=r;
      que.emplace(nv,res[nv]);
    }
  }
  rep(i,n){
    cout<<res[i]<<endl;
  }
}

Measured memory_bytes: 19696
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] l = new int[n];
		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
		}
		sc.close();

		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					if (i != j && j != k
							&& l[i] < l[j] && l[j] < l[k]
							&& l[i] + l[j] > l[k]) {
						ans++;
					}
				}
			}
		}
		System.out.println(ans);
	}
}


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

int main()
{   
    int n;
    cin>>n;
    int a[n];
    
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]-=i+1;
    }
    sort(a,a+n);
    int b=a[n/2];
    long long sum=0;
    for(int i=0;i<n;i++) sum+=abs(a[i]-b);
    cout<<sum<<endl;
  
    
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int A,B,C; cin >> A >> B >> C;
	Yn(A==B && B == C);

	return 0;
}


Measured memory_bytes: 256