akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, M;
    cin >> N >> M;
    vector<ll> x(N), y(N);
    vector<ll> nx(M), ny(M);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];
    for (int i = 0; i < M; i++) cin >> nx[i] >> ny[i];

    for (int i = 0; i < N; i++) {
        int ans = 0;
        ll mi = LINF;
        for (int j = 0; j < M; j++) {
            ll dist = abs(x[i] - nx[j]) + abs(y[i] - ny[j]);
            if (dist < mi) {
                mi = dist;
                ans = j;
            }
        }
        cout << ans + 1 << '\n';
    }
}


Measured memory_bytes: 3608
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node{int p,l,r;};
struct Node T[MAX];
int n;

void preorder(int u){
  if(u==NIL) return;
  printf(" %d",u);
  preorder(T[u].l);
  preorder(T[u].r);
}
void inorder(int u){
  if(u==NIL) return;
  inorder(T[u].l);
  printf(" %d",u);
  inorder(T[u].r);
}
void postorder(int u){
  if(u==NIL) return;
  postorder(T[u].l);
  postorder(T[u].r);
  printf(" %d",u);
}
int main(){
  int i,v,l,r,root;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l!=NIL) T[l].p=v;
    if(r!=NIL) T[r].p=v;
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL) root=i;
  }
  printf("Preorder\n");
  preorder(root);
  printf("\n");
  printf("Inorder\n");
  inorder(root);
  printf("\n");
  printf("Postorder\n");
  postorder(root);
  printf("\n");

  return 0;
  
}



Measured memory_bytes: 2044
import java.util.*;
import java.math.*;

public class Main{
	private static boolean isLeap(int y){
		return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
	}

	private static BigInteger toDay(int y,int m,int d){
		BigInteger res = new BigInteger(Integer.toString(d));

		res = res.add(new BigInteger(Integer.toString((y-1) * 365)));
		for(int i=4;i<y;i++){
			if(isLeap(i)){
				res = res.add(BigInteger.ONE);
			}
		}

		for(int i=1;i<m;i++){
			switch(i){
			case 2:
				if(isLeap(y)) res = res.add(new BigInteger("29"));
				else res = res.add(new BigInteger("28"));
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				res = res.add(new BigInteger("30"));
				break;
			default:
				res = res.add(new BigInteger("31"));
				break;
			}
		}
		return res;
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(true){
			int y1= sc.nextInt();
			int m1= sc.nextInt();
			int d1= sc.nextInt();
			int y2= sc.nextInt();
			int m2= sc.nextInt();
			int d2= sc.nextInt();
			if(y1 == -1) break;
			System.out.println(toDay(y2,m2,d2).subtract(toDay(y1,m1,d1)));
		}
	}
}

Measured memory_bytes: 13000
#include <iostream>

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

	if (a + b == c + d)
		std::cout << "Balanced";
	else if (a + b > c + d)
		std::cout << "Left";
	else
		std::cout << "Right";

    return 0;
}

Measured memory_bytes: 256
s = input()
x = int(s[:2])
y = int(s[2:])
if 1 <= x <= 12 and 1 <= y <= 12:
    a = "AMBIGUOUS"
elif 1 <= x <= 12:
    a = "MMYY"
elif 1 <= y <= 12:
    a = "YYMM"
else:
    a = "NA"
print(a)

Measured memory_bytes: 9108
import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
	private static BufferedReader br = null;
	
	public static void main(String[] args) {
		String[] strs = read(1)[0].split(" ");
		int a = Integer.parseInt(strs[0]);
		int b = Integer.parseInt(strs[1]);
		int n = Integer.parseInt(strs[2]);

		System.out.println((n / a) * b);
	}
	
	private static String[] read(int len) {
		List<String> strList = new ArrayList<>();
		
		try {
			if (br == null) {
				br = new BufferedReader(new InputStreamReader(System.in));
			}
			
			for (int i = 0; i < len; i++) {
				strList.add(br.readLine());
			}
		} catch (IOException e) {
		}
		
		return strList.toArray(new String[0]);
	}
	
	private static void close() {
		try {
			if (br != null) {
				br.close();
			}
		} catch (IOException e) {
		}
	}
}


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

ll a[100001];


int main(){
    ll n,q,b,c;
    ll sum=0;
    cin>>n;
    ll temp;
    for(ll i=0;i<n;++i){
        cin>>temp;
        sum=sum+temp;
        a[temp]++;
    }
    cin>>q;
    while(q--){
        cin>>b>>c;
        ll count=a[b];
        sum = sum-(count*b);
        a[b]=0;
        a[c]=a[c]+count;
        sum = sum+(count*c);
        cout<<sum<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 4344
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
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;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

template<typename T>
struct RollingHash {
	static const int base1 = 1007, base2 = 2009;
	static const int mod1 = 1000000007, mod2 = 1000000009;
	vector<long long> hash1, hash2, power1, power2;
 
	// construct
	RollingHash(const T& S) {
		int n = (int)S.size();
		hash1.assign(n + 1, 0);
		hash2.assign(n + 1, 0);
		power1.assign(n + 1, 1);
		power2.assign(n + 1, 1);
		for (int i = 0; i < n; ++i) {
			hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
			hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
			power1[i + 1] = (power1[i] * base1) % mod1;
			power2[i + 1] = (power2[i] * base2) % mod2;
		}
	}
 
 
	// get hash of S[left:right]
	inline pair<long long, long long> get(int l, int r) const {
		long long res1 = hash1[r] - hash1[l] * power1[r - l] % mod1;
		if (res1 < 0) res1 += mod1;
		long long res2 = hash2[r] - hash2[l] * power2[r - l] % mod2;
		if (res2 < 0) res2 += mod2;
		return { res1, res2 };
	}
};




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

	ll n;
	cin>>n;
	vector<string> s(n);
	REP(i,n) cin>>s[i];

	vector<string> t(n,string(n,'.'));
	REP(i,n){
		REP(j,n){
			t[j][i]=s[i][j];
		}
	}

	vector<RollingHash<string> > rhs,rht;
	REP(i,n) rhs.push_back(RollingHash<string>(s[i]+s[i]));
	REP(i,n) rht.push_back(RollingHash<string>(t[i]+t[i]));

	ll ans=0;
	REP(a,n){
		bool flag=true;
		REP(i,n){
			if(rhs[(i+a)%n].get(i,n)!=rht[i].get(a+i,a+n)){
				flag=false;
				break;
			}
			
		}
		if(flag) ans++;
	}

	cout<<ans*n<<endl;

	return 0;
}


Measured memory_bytes: 11904
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.d = [-1] * n

    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        else:
            if self.d[x] > self.d[y]:
                x, y = y, x
            self.d[x] += self.d[y]
            self.d[y] = x
            return True

    def same(self, x, y):
        return self.find(x) == self.find(y)


    def size(self, x):
        return -self.d[self.find(x)]
N,M = map(int,input().split())
uf = UnionFind(N)
for i in range(M):
    A,B = map(int,input().split())
    uf.unite(A-1,B-1)
minus = 0
cnt = set()
for i in range(N):
    if uf.find(i) == '-1':
        minus += 1
    else:
        cnt.add(uf.find(i))
print(len(cnt)+minus-1)



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

using namespace std;

using ll = long long;
constexpr ll MOD = 998244353;
constexpr ll INF = 1e18;

int main() {
    ll n, i, j, s;
    cin >> n >> s;
    vector<ll> A(n);
    for(auto &x : A) cin >> x;
    vector<vector<ll>> dp(n + 1, vector<ll>(6001, 0));
    dp[0][0] = 1;
    for(i = 0; i < n; i++) {
        for(j = 0; j <= s; j++) {
            (dp[i + 1][j + A[i]] += dp[i][j]) %= MOD;
            (dp[i + 1][j] += dp[i][j]) %= MOD;
        }
        dp[i + 1][0] = i + 2;
    }
    ll ret = 0;
    for(i = 0; i < n; i++) (ret += dp[i + 1][s]) %= MOD;
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 141056
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
 
using namespace std;

vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
#define MOD 1000000007
#define A first
#define B second
#define all(x) (x).begin(), (x).end

typedef long long ll;
 
inline int mulmd(ll a, ll b){
  ll ret = (a * b) % MOD;
  return (int) ret;
}
 
inline int power(ll x, ll y, int m){
  ll res = 1;
  x = x % m;
  while(y > 0){
    if(y & 1){
      res = mulmd(res, x);
    }
    y = y >> 1;
    x = mulmd(x, x);
  }
  return (int) res;
}
 
inline int submd(ll a, ll b){
  ll ret = (a - b);
  if(ret < 0) ret += MOD;
  return (int) ret;
}
 
inline int addmd(ll a, ll b){
  ll ret = (a + b) % MOD;
  return (int) ret;
}
 
inline int invPow(ll a){
  return power(a, MOD - 2, MOD);
}
 
inline int divmd(ll a, ll b){
  ll ret = mulmd(a, invPow(b));
  return (int) ret;
}
 
const int N = 1e2 + 5;

int arr[N];
ll weights[N];
ll values[N];
ll dp[N][100005];

void solve(){
  int n, w;
  cin >> n >> w;
  for(int i = 0; i < n; i++){
    cin >> weights[i] >> values[i];
  }
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= w; j++){
      if(i == 0 || j == 0) dp[i][j] = 0;
      else if(weights[i - 1] <= j){
        dp[i][j] = max(values[i - 1] + dp[i - 1][j - weights[i - 1]], dp[i - 1][j]);
      }
      else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }
  cout << dp[n][w];

}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
}



Measured memory_bytes: 82540
package main

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

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	split := strings.Split(s.Text(), " ")

	d := make([]int, k)
	for i, s := range split {
		d[i], _ = strconv.Atoi(s)
	}

	base := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	fav := make([]int, 0, len(base)-k)
l1:
	for _, b := range base {
		for _, v := range d {
			if b == v {
				continue l1
			}
		}
		fav = append(fav, b)
	}

l2:
	for i := n; i < n*10; i++ {
		var ns []int
		ns = digit(i, ns)

		for j := 0; j < len(ns); j++ {
			var valid bool
			for _, v := range fav {
				if ns[j] == v {
					valid = true
				}
			}
			if !valid {
				continue l2
			}
		}

		fmt.Printf("%d", i)
		break
	}
}

func digit(i int, list []int) []int {
	if i > 0 {
		return digit(i/10, append(list, i%10))
	}
	return list
}

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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

bool solve(int a,int b,int c){
    if(b>c-a) return true;
    else return false;
}

int main(){
    int N; cin >> N;
    vector<int> l(N);
    for(int i=0;i<N;i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    int ans=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            int iter=lower_bound(l.begin(),l.end(),l[j]+l[i])-l.begin();
            ans+=iter-(j+1);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>

using namespace std;
typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP[6000] = {};

int main(){
  DP[0] = 1;
  for(int loop = 0; loop < 4; loop++){
    for(int j = 4000; j >= 0; j--){
      for(int k = 1; k <= 1000; k++){
        DP[j + k] += DP[j];
      }
    }
  }
  while(true){
    int n;
    cin >> n;
    if(cin.eof()){
      break;
    }
    cout << DP[n] << endl;
  }
  return 0;
}



Measured memory_bytes: 3156
#include <iostream>

using namespace std;

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

    if (N < 105)
    {
        cout << 0 << endl;
    }
    else
    {
        int valNum = 0;
        for (int i = 105; i <= N; i += 2)
        {
            int num = 0;
            for (int j = 1; j <= N; j++)
            {
                if (i % j == 0)
                    num++;
            }
            if (num == 8)
            {
                valNum++;
            }
        }
        cout << valNum << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
import collections

n = int(input())

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


l = [a[i] +i+1 for i in range(n)]
r = [i+1 -a[i] for i in range(n)]

L = collections.Counter(l)
R = collections.Counter(r)

c = 0

for i in L.keys():
    c += L.get(i, 0) * R.get(i, 0)

print(c)

Measured memory_bytes: 63448
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) int(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define SIZE 26     
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
 
const ll mod = 1e9 + 7;
const int inf = 1e9 + 5;
const int N = 1e2 + 5;

ll weight[N],val[N];

signed main(){
    fastio;
    ll i,j,n,w;
    cin>>n>>w;
    ll dp[n+1][w+1];
    for(i=1;i<=n;i++){
        cin>>weight[i]>>val[i];
    }
    for(i=0;i<=n;i++){
        dp[i][0]=0;
    }
    for(j=0;j<=w;j++){
        dp[0][j]=0;
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=w;j++){
            dp[i][j]=dp[i-1][j];
            if(j-weight[i]>=0){
                dp[i][j]=max(dp[i][j],val[i]+dp[i-1][j-weight[i]]);
            }
        }
    }
    cout<<dp[n][w];
    return 0;
}

Measured memory_bytes: 79232
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = int(input())
    for i in range(1,10):
        if N % i == 0:
            if N // i < 10:
                print('Yes')
                return
    print('No')



if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
s = input()
t = input()
R1 = {i:-1 for i in "abcdefghijklmnopqrstuvwxyz"}
R2 = {i:-1 for i in "abcdefghijklmnopqrstuvwxyz"}
for i in range(len(s)):
    if R1[s[i]] != -1:
        if R1[s[i]] != t[i]:
            print("No")
            break
    else:
        R1[s[i]] = t[i]
    if R2[t[i]] != -1:
        if R2[t[i]] != s[i]:
            print("No")
            break
    else:
        R2[t[i]] = s[i]
else:
    print("Yes")

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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  char d='a';
  for(int i=0;i<301;i++){
    if(d=='a'){
      if(a==""){
        break;
      }
      d=a[0];
      a=a.substr(1,a.size()-1);
    }
    if(d=='b'){
      if(b==""){
        break;
      }
      d=b[0];
      b=b.substr(1,b.size()-1);
    }
    if(d=='c'){
      if(c==""){
        break;
      }
      d=c[0];
      c=c.substr(1,c.size()-1);
    }
  }
  cout << char(d+'A'-'a') << endl;
}
  

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string t = "MARCH";
    int c[5] = {};
    rep(i, 0, n){
        string s;
        cin >> s;
        if(t.find(s[0]) != string::npos){
            c[t.find(s[0])]++;
        }
    }
    int ans = 0;
    rep(i, 0, 5){
        rep(j, i + 1, 5){
            rep(k, j + 1, 5){
                ans += c[i] * c[j] * c[k];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void print(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void print(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;



int a[200000], b[2][200000];
signed main(){
  int n, k;
  cin >> n >> k;
  rrep(i,n)cin >> a[i];
  rrep(i,n){
    b[0][i] = max(0LL, a[i]);
    b[1][i] = min(0LL, a[i]);
    b[0][i] += b[0][i-1];
    b[1][i] += b[1][i-1];
  }
  int ans = 0;
  rrep(i,n){
    int l = i, r = i+k;
    if(r > n+1)break;
    int sum = 0;
    sum += (b[0][l-1]-b[0][0]);
    sum += (b[0][n]-b[0][r-1]);
    // cout << l << " " << r << endl;
    int x = b[0][r-1]-b[0][l-1];
    int y = b[1][r-1]-b[1][l-1];
    sum += max(0LL, x+y);
    chmax(ans, sum);
    // cout << ans << endl;
  }
  cout << ans << endl;
	return 0;
}










Measured memory_bytes: 3584
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>
 
using namespace std;
 
 
 
int main() {
    int d,i,j,k;
    int c[26];
    int s[365][26];
    cin >> d;
    for(i = 0; i < 26; ++i) cin >> c[i];
    for(i = 0; i < d; ++i) for(j = 0; j < 26; ++j) cin >> s[i][j];
 
    int arr[365] = {};
 
    int t1,t2,s1,s2, diff, count;
    count = 0;
    int max, loc;
    int a[26] = {};
    int b[26] = {};
    for(i = 0; i < 365; ++i) {
        for(j = 0; j < 26; ++j) {
            b[j] = s[i][j]+(a[j]*a[j]*c[j])/10;
            a[j]++;
        }
        max = *max_element(b,b+26);
        loc = find(b,b+26,max)-b;
        arr[i] = loc;
        a[loc] = 0;
    }
    
    
    while(true) {
        label1:
        for(i = 0; i < d; ++i) {
            for(j = 0; j < 26; ++j) {
                if(arr[i]==j) continue;
                if(count>20000000) goto label2;
                ++count;
                for(s1 = i+1; s1 < d; ++s1) {
                    if(arr[s1]==arr[i]) break;
                }
                for(t1 = i-1; t1 >= 0; --t1) {
                    if(arr[t1]==arr[i]) break;
                }
                for(s2 = i+1; s2 < d; ++s2) {
                    if(arr[s2]==j) break;
                }
                for(t2 = i-1; t2 >= 0; --t2) {
                    if(arr[t2]==j) break;
                }
                diff = s[i][j]-s[i][arr[i]]+(((s1-i)*(s1-i-1))/2+((i-t1)*(i-t1-1))/2-((s1-t1)*(s1-t1-1))/2)*c[arr[i]] + (-((s2-i)*(s2-i-1))/2-((i-t2)*(i-t2-1))/2+((s2-t2)*(s2-t2-1))/2)*c[j];
                if(diff>0) {
                    arr[i] = j;
                    goto label1;
                }
            }
        }
    }
    label2:
    for(i = 0; i < d; ++i) {
        cout<<(arr[i]+1)<<"\n";
    }
 
 
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int n,m,a[201]={},s=0;
bool cmp(int x,int y){return x>y;}
int main()
{
	cin>>n;m=2*n;
	for(int i=1;i<=m;i++)cin>>a[i];
	sort(a+1,a+m+1,cmp);
	for(int i=1;i<=m;i++)if(i%2==0)s+=a[i];
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int a, b, sum = 0;
  int i = 0, j = 1;
  scanf("%d",&a);
  scanf("%d",&b);
  if(b == 1){
    j--;
  }
  i = i + a;
  for(; i < b;){
    j++;
    i = i + a -1;
  }
  printf("%d",j);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>

#define rep(j, n) for (int i = j; i < n; i++)
#define repd(j, n) for (int i = j; i > n; i--)
#define maxx 100010

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

int gcd(int x,int y) {
	for (int j = 0;x!=0&&y!=0; j++) {
		y = y % x;
		if (y != 0) { x = x % y; }
	}
	if (x == 0) {
		return y;
	}
	else {
		return x;
	}
}

int main() {
	int a,ans = 0;
	cin >> a;
	vector<ll> s(a);
	rep(0, a) {
		cin >> s[i];
	}
	ans = s[0];
	rep(1, a) {
		ans = gcd(ans, s[i]);
	}
	cout << ans;
		return 0;
}

Measured memory_bytes: 1024
/** Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std;

#define ll long long // -2^63 to +2^63-1 (upper limit ~ 9*(10^18))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//code
	ll int a,b,k;
	cin>>a>>b>>k;
	if(a >= k)
	{
		a -= k;
	}
	else
	{
		k -= a;
		a = 0;
		b -= k;
	}
	if(b < 0)	b=0;
	cout<<a<<" "<<b;
	return 0;
}


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

fn main() {
    let n: usize = read();
    let a: Vec<f64> = (0..n).map(|_| read::<f64>()).collect();
    let mut sum: f64 = 0.0;
    for i in 0..n {
        sum += a[i];
    }
    let ave: f64 = sum as f64 / (n as f64);
    let mut dis = 100000.0;
    let mut ans = 0;
    for i in 0..n {
        let mut d = ave - a[i];
        if d < 0.0 {
            d = -d;
        }
        if d < dis {
            dis = d;
            ans = i;
        }
    }
    println!("{}", ans);
}

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")
}


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

struct process {
  string name;
  int time;
};

int n, q, head = 1, tail = 0;
process Q[100010];

void enqueue(process p) {
  Q[tail] = p;
  if (tail >= n) tail = 0;
  else tail++;
}

process dequeue(void) {
  process ret = Q[head];
  if (head >= n) head = 0;
  else head++;
  return ret;
}

int main(void) {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    process p;
    cin >> p.name >> p.time;
    Q[i] = p;
  }

  int _time = 0;
  while (head != tail) {
    process p = dequeue();
    // cout << p.name << " " << p.time << endl;
    if (p.time <= q) {
      _time += p.time;
      cout << p.name << " " << _time << endl;
    } else {
      p.time -= q;
      _time += q;
      enqueue(p);
    }
  } 
  return 0;
}

Measured memory_bytes: 5116
import java.util.Scanner;
public class Main{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
int a[]=new int[3000];
int b[]=new int[3000];
int x=0;
int y=0;
int i=0;
int count=0;
int count2=0;
do {
	x=scan.nextInt();
	y=scan.nextInt();
	a[i]=x;
	b[i]=y;
	i++;
}while(!(x==0&&y==0));
i=0;
do {
	do{
		if(a[i]==count2){ 
			count2=0;
			break;
			}
		
		do {
		if(b[i]==count){ 
			count=0;
			break;
			}
		System.out.print("#");
		count++;
	}while(true);
	count2++;
	System.out.println();
	}while(true);
		i++;
		System.out.println();
}while(!(a[i]==0&&b[i]==0));
}
}


Measured memory_bytes: 35788
#ABC074C
A,B,C,D,E,F=map(int,input().split())
ans=0
sw=100*A #SugarWater
s=0 #Sugar
for a in range(0,F+1,100*A):
	for b in range(0,F-a+1,100*B):
		if a+b!=0:
			for c in range(0,F-a-b+1,C):
				for d in range(0,F-a-b-c+1,D):
					if (c+d)/(a+b)<=E/100:
						if ans < (c+d)/(a+b+c+d):
							ans=(c+d)/(a+b+c+d)
							sw=a+b+c+d
							s=c+d
print(sw,s)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,P> pip;
const int inf=(1<<31)-1;

int n;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int a,b,c;
		cin>>a>>b>>c;
		a*=a;
		b*=b;
		c*=c;
		if(a==b+c||b==c+a||c==a+b) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N;
	cin >> N;
    ll ans = 0;
    ll num[10][10]= {};
    ll x,y;
    rep(i,N){
        x = (i+1)%10;
        y = (i+1);
        while(y>=10){
            y=y/10;
        }
        num[x][y]++;
    }

    rep(i,9){
        for(int j=i;j<9;j++){
            if(i+1==j+1){
                ans += (ll)pow(num[i+1][j+1],2);
            }else{
                ans += num[i+1][j+1]*num[j+1][i+1]*2;
                
            }
        }
    }

    cout<<ans<<"\n";
	return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  string s;
  cin >> s;
  for ( int i=0; i<n+m+1; i++ ) {
    if ( i==n ) {
      if ( s[i]!='-' ) {
        puts("No");
        return 0;
      }
    }
    else if ( !isdigit(s[i]) ) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm> 
using namespace std;
int main()
{
	long long n,a,b,i,j,sum=0,p1,p2,p;
	cin>>n>>a>>b;
	p=a+b;
	p1=n/p;
	p2=n%p;
	if(p2>a)
		sum+=p1*a+a;
	if(p2<=a)
		sum+=p1*a+p2;
	cout<<sum;
}

Measured memory_bytes: 888
#include <stdio.h>

void outPut(int Array[],char mark){
	for(int i = 1; i <= 13; i++){
		if(Array[i] == 0) printf("%c %d\n",mark,i);
	}
}

int main(){
	char mark[2];
	int n,S[14],H[14],C[14],D[14],tmp;
	for(int i = 0; i < 14; i++) S[i] = H[i] = C[i] = D[i] = 0;
	scanf("%d",&n);

	for(int i = 0; i < n; i++){
		scanf("%s %d",mark,&tmp);
		switch(mark[0]){
		case 'S':
			S[tmp] = 1;
			break;
		case 'H':
			H[tmp] = 1;
			break;
		case 'C':
			C[tmp] = 1;
			break;
		case 'D':
			D[tmp] = 1;
			break;
		}
	}
	outPut(S,'S');
	outPut(H,'H');
	outPut(C,'C');
	outPut(D,'D');
}


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

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

using namespace std;

int n;
vector<int> b;
int a[101];
int ans=1;

int main() {
    cin>>n;
    for(int i=0;i<n;i++){
        int p;
        cin>>p;
        b.push_back(p);
    }
    for(int i=0;i<n;i++){
        int num;
        bool pos=false;
        for(int j=0;j<b.size();j++){
            if(b[j]==j+1){
                num=j;
                pos=true;
            }
        }
        if(pos==false){
            ans=-1;
            break;
        }
        a[i]=b[num];
        b.erase(b.begin()+num);
    }
    if(ans<0){
        cout<<-1;
    }else{
        for(int i=0;i<n;i++){
            cout<<a[n-1-i]<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
int main(void){
    // Your code here!
    
    int n;
    cin>>n;
    
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>vec[i];
    }    
    int count=0;
    for(int i=1;i<n-1;i++){
        if((vec[i]>vec[i-1] && vec[i]<vec[i+1]) ||(vec[i]>vec[i+1] && vec[i]<vec[i-1])){
            count++;
        }
    }
    cout<<count;
    
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int A, B;
	cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
length = int(input())
string = input()

if(length % 2 == 1):
    print('No')
else:
    key = 0
    for i in range(length // 2):
        if(string[i] != string[length//2 + i]):
            key = 1

    if(key == 0):
        print('Yes')
    else:
        print('No')


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

#define rep(i, first, to) for(ll i = first; i < to; ++i)

using namespace std;
typedef long long ll;

void solve() {
	int x;
	cin >> x;
	cout << (800 * x - (x / 15) * 200) << endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,z=1;
  cin>>n;
  int a[n],b[1000000],c=0;
  for(int i=0;i<n;i++)cin>>a[i];
  if(n==2){
    while(z<=a[0]||z<=a[1]){
      if(a[0]%z==0&&a[1]%z==0){
	b[c]=z;
	c++;
      }
      z++;
    }
  }if(n==3){
    while(z<=a[0]||z<=a[1]||z<=a[2]){
      if(a[0]%z==0&&a[1]%z==0&&a[2]%z==0){
	b[c]=z;
	c++;
      }
      z++;
    }
  }
  for(int i=0;i<c;i++)cout<<b[i]<<endl;
}

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

int main(void){
    // Your code here!
   string a, b, c;
   cin >> a >> b >> c;
   char dif = 'A' - 'a';
   printf ("%c%c%c\n",a[0]+dif,b[0]+dif,c[0]+dif);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
  int a, b, c, d, e;
  int k;
  scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);
  (e - a > k) ? printf(":(\n") : printf("Yay!\n");
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    string a, b;
    cin >> a >> b;
    int n = a.size();
    for (int i = 0; i < n; i++) {
        if (a == b) {
            cout << "Yes";
            return 0;
        }
        a = a.substr(1, (unsigned long) (n - 1)) + a[0];
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  int x, y;
  cin >> x >> y;
  cout << x + y / 2 << endl;
}

Measured memory_bytes: 256
let rec pow x n = if n = 1 then x else x * pow x (n - 1)

let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = Array.init n @@ fun _ ->
  let l = Scanf.sscanf (read_line ()) "%d" @@ fun l -> l in
  Array.init l @@ fun _ -> Scanf.sscanf (read_line ()) "%d %d" @@ fun x y -> (x - 1, y)

let x = pow 2 n

let rec to_list x = function
  | 0 -> []
  | n -> x mod 2 :: to_list (x / 2) (n - 1)

let f arr = 
  let res = Array.mapi(fun i t ->
    Array.fold_left (fun z (x, y) -> 
      z && (t = 0 || arr.(x) = y)
    ) true a.(i)
  ) arr in
  Array.fold_left (&&) true res

let rec loop m i = 
  if i = x then m 
  else begin
    let arr = Array.of_list @@ to_list i n in
    loop (if f arr then max m (Array.fold_left (+) 0 arr) else m) (i + 1)
  end

let () = Printf.printf "%d\n" @@ loop 0 0

Measured memory_bytes: 2560
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
	array<int,3> in;
	for(auto&e:in)cin >> e;
	sort(begin(in), end(in));
	int ans = 0;
	do {
		ans = max(ans, in[0] + in[1]*10 + in[2]);
	} while(next_permutation(begin(in), end(in)));
	cout << ans << endl;
}


Measured memory_bytes: 256
def LI():
    return list(map(int, input().split()))


def LIHW(h):
    return [list(map(int, input().split())) for _ in range(h)]


N, M = LI()
Nlist = LIHW(N)
Mlist = LIHW(M)
anslist = [0]*N
for i in range(N):
    a, b = Nlist[i]
    ans = 10**9
    for j in range(M):
        c, d = Mlist[j]
        kyori = abs(c-a)+abs(d-b)
        if ans > kyori:
            ansind = j+1
            ans = kyori
    anslist[i] = ansind

for i in range(N):
    print(anslist[i])


Measured memory_bytes: 9168
//17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
#define ff  first
#define ss  second
#define pb  push_back
#define ll  long long
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define ld  long double
#define eb  emplace_back
#define ull unsigned long long
#define all(v) v.begin(), v.end()
#define f(i,x,n)  for(int i=x;i<n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
#define bolt ios::sync_with_stdio(false)
using namespace std;

void IoI() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

int32_t main() {
	//IoI();
	bolt;
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	ll n, m; cin >> n >> m;
	vector <ll> ar(n); ll sum = 0;
	f (i, 0, n) {
		cin >> ar[i];
		sum += ar[i];
	}
	ll x = ceil((double)sum / (double)(4.0 * (double)m)); bool flag = true;
	//cout << x << endl;
	ll p = 0;
	f (i, 0, n) {
		if (ar[i] >= x) {
			p++;
		}
	}
	if (p >= m) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
 

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, L, mi, ni;
  cin >> N >>M;
  L = M*2;
  vector<int> vec(L);
  for(int i=0;i<M;i++) {
    cin >>mi >>ni;
    vec.at(i) =mi;
    vec.at(i+M)=ni;
    }
  int count=0;
for(int i=1;i<=N;i++){
  count =0;
  for(int j=0;j<L;j++)if(vec.at(j)==i) count++;
  
  cout << count << endl;
}
    }

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 998244353;

long long int a[110000], b[110000], c[110000];

int main(){
	long long int N, K;
	cin >> N >> K;
	if(N % 2 == 1){
		if((K + (K + 2 * N - 1)) * 2 > (K + 2 * N) + (K + 3 * N - 1)){
			cout << -1 << endl;
			return 0;
		}
	}else{
		if((K + (K + 2 * N - 1)) * 2 + 1 > (K + 2 * N) + (K + 3 * N - 1)){
			cout << -1 << endl;
			return 0;
		}
	}
	for(int i = 0; i < N; i++){
		c[i] = K + 2 * N + i;
	}
	if(N % 2 == 1){
		for(int i = 0; i < N; i += 2){
			a[i] = K + i / 2;
			b[i] = K + 2 * N - 1 - N / 2 + i / 2;
		}
		for(int i = 1; i < N; i += 2){
			a[i] = K + (N + 1) / 2 + i / 2;
			b[i] = K + N + i / 2;
		}
	}else{
		a[0] = K;
		b[0] = K + 2 * N - 1 - N / 2;
		for(int i = 1; i < N; i += 2){
			a[i] = K + i / 2 + 1;
			b[i] = K + 2 * N - 1 - N / 2 + i / 2 + 1;
		}
		for(int i = 2; i < N; i += 2){
			a[i] = K + N / 2 + i / 2;
			b[i] = K + N + i / 2 - 1;
		}
	}
	for(int i = 0; i < N; i++){
		cout << a[i] << " " << b[i] << " " << c[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4608
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<vector<ll>> edge;

pll dfs(ll w,ll p){
    pll ret={1,w};
    for(auto &I:edge[w]){
        if(I!=p){
            pll A=dfs(I,w);
            A.F++;
            if(A>ret){ret=A;}
        }
    }
    return ret;
}


int main(){
    ll n;
    cin>>n;
    edge.resize(n);
    for(int i=1;i<n;i++){
        ll a,b;
        cin>>a>>b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    pll A=dfs(0,-1);
    ll L=dfs(A.S,-1).F;
    cout<<(L%3==0 || L%3==1?"First":"Second")<<endl;
    
    return 0;
}


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

#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e10

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; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;
void chmin(ll &a, ll b) { if (a > b) a = b; }

int n;
vector<int> l;
int A, B, C;

ll select(int k, int a, int b, int c)
{

    if(k == n){
        if (!(a-A) || !(b-B) || !(c-C)) return INF;
        return abs(a) + abs(b) + abs(c);
    }
    ll res = select(k+1, a, b, c);
    chmin(res, select(k+1, a-l[k], b, c)+((A-a)?10 : 0));
    chmin(res, select(k+1, a, b-l[k], c)+((B-b)?10 : 0));
    chmin(res, select(k+1, a, b, c-l[k])+((C-c)?10 : 0));
    return res;
}

int main()
{
    int a, b, c;
    cin >> n >> a >> b >> c;
    A = a;
    B = b;
    C = c;
    l.resize(n);
    rep(i, n){
        cin >> l[i];
    }
    ll count = select(0, a, b, c);
    cout << count;
}

Measured memory_bytes: 256
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define INF (int)1e9 + (int)1e8
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

class graph{
public:
    vector<ll>* adjList;
    vector<vector<ll> > dp;
    graph(ll n){
        adjList = new vector<ll>[n];
        dp = vector<vector<ll> >(n, vector<ll>(2, -1));
    }
    void addEdge(ll u, ll v){
        adjList[u].push_back(v);
        adjList[v].push_back(u);
    }
    ll dfs(ll curr, ll par, ll color){
        if(dp[curr][color]!=-1) return dp[curr][color];
        ll ans1 = 1;
        for(auto ch: adjList[curr]){
            if(ch!=par){
                if(color==1){
                    ans1*=((dfs(ch, curr, 1)+dfs(ch, curr, 0))%mod);
                    ans1%=mod;
                }
                else{
                    ans1*=dfs(ch, curr, 1);
                    ans1%=mod;
                }
            }
        }
        return dp[curr][color]=ans1;
    }
};

int main(){
    cpp();
    ll n;
    cin>>n;
    graph g(n);
    for(ll i=0; i<n-1; i++){
        ll x, y;
        cin>>x>>y;
        g.addEdge(--x, --y);
    }
    ll ans = (g.dfs(0, -1, 1)+g.dfs(0, -1, 0))%mod;
    cout<<ans<<endl;
    return 0;
}






Measured memory_bytes: 23796
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

template<ll mod> struct Mod_Int{
    ll x;
    Mod_Int() {}
    Mod_Int(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}

    Mod_Int &operator += (const Mod_Int &p) {
        x = (x + p.x) % mod;
        return *this;
    }

    Mod_Int &operator -= (const Mod_Int &p) {
        x = (x + mod - p.x) % mod;
        return *this;
    }

    Mod_Int &operator *= (const Mod_Int &p) {
        x = (x * p.x) % mod;
        return *this;
    }

    Mod_Int &operator /= (const Mod_Int &p) {
        *this *= p.inverse();
        return *this;
    }

    Mod_Int operator -() const {return Mod_Int(-x);}

    Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;}

    Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;}

    Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;}

    Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;}

    bool operator == (const Mod_Int &p) const {return x == p.x;}

    bool operator != (const Mod_Int &p) const {return x != p.x;}

    Mod_Int pow(ll n) const{
        Mod_Int now = *this, ret = 1;
        while(n > 0){
            if(n & 1) ret *= now;
            now *= now, n >>= 1;
        }
        return ret;
    }

    Mod_Int inverse() const{
        return pow(mod-2);
    }
};

using mint = Mod_Int<MOD>;
const int MAX_N = 1e5;
mint fac[MAX_N+1];

void init(){
    fac[0] = 1;
    rep2(i, 1, MAX_N){
        fac[i] = fac[i-1]*mint(i);
    }
}

mint comb(mint n, mint k){
    return fac[n.x]/(fac[n.x-k.x]*fac[k.x]);
}

mint perm(mint n, mint k){
    return fac[n.x]/fac[n.x-k.x];
}

int main(){
    int N; ll A, B;
    cin >> N >> A >> B;
    if(A > B) swap(A, B);
    ll S[N+2];
    S[0] = -INF, S[N+1] = 2*INF;
    rep2(i, 1, N) cin >> S[i];
    rep(i, N){
        if(S[i+2]-S[i] < A) {cout << 0 << endl; return 0;}
    }
    vector<int> steps;
    steps.pb(0);
    rep(i, N+1){
        if(S[i+1]-S[i] < A) steps.pb(i);
    }
    mint dp[N+2], sum[N+3];
    sum[0] = 0, dp[0] = 1, sum[1] = 1;
    int nowa = 0, nowb = 0, n = steps.size();
    rep2(i, 1, N+1){
        while(nowa < n-1 && steps[nowa+1] < i-1) nowa++;
        while(nowb < i && S[i]-S[nowb] >= B) nowb++;
        int l = steps[nowa], r = nowb;
        //cout << l << ' ' << r << endl;
        if(l >= r) dp[i] = 0;
        else dp[i] = sum[r]-sum[l];
        sum[i+1] = sum[i]+dp[i];
    }
    cout << dp[N+1].x << endl;
}

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] num = new long[n];
        long m = (long)(Math.pow(10, 9) + 7);
        long sum = 0;
        for (int i = 0; i < n; i++) {
            num[i] = sc.nextLong();
            sum += num[i];
            sum %= m;
        }
        long result = 0;
        for (int i = 0; i < n; i++) {
            sum -= num[i];
            if (sum < 0) {
                sum += m;
            }
            result += num[i] * sum;
            result %= m;
        }
        System.out.println(result);
    }

}


Measured memory_bytes: 62904