akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
//const ll big=998244353;
const ll big=1000000007LL;
const ll INF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
    if(x>y)return x;
    else return y;
}
ll min(ll x,ll y){
    if(x<y)return x;
    else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}

int n,m;
int points(){return 0;}
int point(int i,int j){return m*i+j+1;}//頂点番号は1→mn
int pointg(){return n*m+1;}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    cin >> n >> m;
    vector<vector<char>> grid(n,vector<char>(m));
    rep(i,n)rep(j,m)cin >> grid[i][j];

    vector<pair<pair<int,int>,pair<int,int>>> es;//edges[i]=i番目に追加した辺

    mf_graph<int> g(n*m+2);
    rep(i,n)rep(j,m){
        if(grid[i][j]=='#')continue;
        if((i+j)%2==0){
            g.add_edge(points(),point(i,j),1);
            es.push_back({{-1,-1},{i,j}});//スタートは(-1,-1)なる座標だと思うことにする
        }
        else{
            g.add_edge(point(i,j),pointg(),1);
            es.push_back({{i,j},{n,m}});//ゴールは(n,m)なる点だと思うことにする
        }
        rep(k,4){
            //(i+j)%2==0ならそっちがfrom
            int ni=i+dx[k],nj=j+dy[k];
            if(ni<0||nj<0||ni>=n||nj>=m||grid[ni][nj]=='#')continue;
            if((i+j)%2==0){
                g.add_edge(point(i,j),point(ni,nj),1);
                es.push_back({{i,j},{ni,nj}});
            }
            else{
                g.add_edge(point(ni,nj),point(i,j),1);
                es.push_back({{ni,nj},{i,j}});
            }
        }
    }
    int res=g.flow(points(),pointg());
    cout << res << endl;

    vector<vector<char>> ans=grid;
    rep(i,es.size()){
        auto now=g.get_edge(i);
        if(now.from==points()||now.to==pointg())continue;
        if(now.flow==0)continue;
        //now.fromからnow.toへ1だけflowが流れているので、タイルがおける
        pair<int,int> s=es[i].first , t=es[i].second;
        if(s>t)swap(s,t);
        if(s.first == t.first){
            ans[s.first][s.second]='>';
            ans[t.first][t.second]='<';
        }else{
            ans[s.first][s.second]='v';
            ans[t.first][t.second]='^';
        }
    }
    rep(i,n){
        rep(j,m)cout << ans[i][j];
        cout << '\n';
    }
}

Measured memory_bytes: 7000
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef unsigned long long ll;

ll N, n, M, K;

int main(){
    cin >> N ;
    vector< pair<pair<string, int>, int>> p;
    REP(i,N){
        string s; int cost;
        cin >> s >> cost;
        p.push_back( make_pair( make_pair(s, -cost),i+1  ) );
    }
    sort(p.begin(), p.end());
    REP(i,N){
        cout<< p[i].second<<"\n";
    }
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.IO;

public class Playground
{
    //private static List<string[]> item = new List<string[]>();

    public static void Main(string[] args)
    {
        Input();
        //Method();
        System.Console.ReadLine();
    }

    private static void Input()
    {
        var dic = new HashSet<string>();
        int num = int.Parse(Console.ReadLine());
        var sb = new StringBuilder();
        for (int i = 0; i < num; i++)
        {
            var ope = (Console.ReadLine().Split(' '));
            if (ope[0][0] == 'i')
            {
                dic.Add(ope[1]);
            }
            else
            {
                if (dic.Contains(ope[1]))
                {
                    sb.AppendLine("yes");
                }
                else
                {
                    sb.AppendLine("no");
                }
            }
        }
        Console.Write(sb.ToString());
    }

    //private static void Method()
    //{
    //    //var dic = new Dictionary<int, string>();
    //    var dic = new HashSet<string>();
    //    foreach (var ope in item)
    //    {
    //        if (ope[0].Equals("insert"))
    //        {
    //            dic.Add(ope[1]);
    //        }
    //        else
    //        {
    //            if (dic.Contains(ope[1]))
    //            {
    //                Console.WriteLine("yes");
    //            }
    //            else
    //            {
    //                Console.WriteLine("no");
    //            }
    //        }
    //    }
    //}
}

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

int main() {
  int  N , a = 0;
  cin >> N ;
  int n = N , k=100000000 ;
    for (int i = 8 ; i >= 0 ; i-- , k/=10){
        a += N / k ;
        N %= k ;
    }
  if ( n%a == 0)
        cout << "Yes" << endl ;
    else
        cout << "No" << endl ;
}



Measured memory_bytes: 256
import std.stdio,std.conv,std.algorithm,std.array;

int[] 		raia()	{ return readln().split().map!(to!int).array; }		//read stdin as int[]

void main(){
	for(auto i =0; i< 10000;i++)
	{auto it = raia();
		if(it[0] == 0 && it[1] == 0){ return;}
		else if( it[0] > it[1]){
			writeln(it[1]," ",it[0]);
		}else{
			writeln(it[0]," ",it[1]);
		}
	}
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
void main_sub(void);
int main(int argc, char* argv[]) {
    main_sub();
    return 0;
}
// int を int64_t にする
// g++ に -DUSE_STRICT_INT をつけるか、
// 下のコメントアウトを外すと無効化
#define USE_STRICT_INT
using i64 = int64_t;
#ifndef USE_STRICT_INT
#define int i64
#endif
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = (1 << 30);
constexpr i64 INFL = (1LL << 62);
constexpr i64 MOD = 1000000007;

void main_sub(void) {
    string s;
    cin >> s;
    int n = s.size();
    deque<int> d(n);
    rep(i, n) { d[i] = s[i] - 'a'; }
    int q;
    cin >> q;
    bool hanten = false;
    rep(i, q) {
        int t;
        cin >> t;
        if (t == 1) {
            hanten = !hanten;
        } else {
            int f;
            cin >> f;
            char c;
            cin >> c;
            if (hanten) {
                if (f == 2) {
                    d.push_front(c - 'a');
                } else {
                    d.push_back(c - 'a');
                }
            } else {
                if (f == 1) {
                    d.push_front(c - 'a');
                } else {
                    d.push_back(c - 'a');
                }
            }
            ++n;
        }
    }
    if (hanten) {
        for (int i = n - 1; i >= 0; --i) {
            printf("%c", d[i] + 'a');
        }
        printf("\n");
    } else {
        for (int i = 0; i < n; ++i) {
            printf("%c", d[i] + 'a');
        }
        printf("\n");
    }
    return;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const ll mod=998244353;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res%mod;}
long modInverse(long a) {return powmod(a, mod-2);}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,m;
    cin>>n>>m;
    ll res=n*(n-1)/2;
    res+=(m*(m-1)/2);
    cout<<res<<endl;
    return 0;
    }


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


int main() {
  int n,k;
  cin >>n >>k;
  vector<int> h(n);
  for(int i=0;i<n;i++)cin >>h[i];
  if(k >= n) cout << 0 <<endl;
  else {
   sort(h.begin(),h.end());
    int s = n - k;
      int64_t ans =0;
      for(int i=0;i<s;i++) ans += h[i];
    cout <<ans <<endl;
  }
}

Measured memory_bytes: 1024
import itertools

n,m = map(int,input().split())
path=[[False]*n for _ in range(n)]
for _ in range(m):
  a,b = map(int,input().split())
  a-=1
  b-=1
  path[a][b]=True
  path[b][a]=True
ans=0

for i in itertools.permutations(range(n),n):
   if i[0] == 0:
     for j in range(n):
       if j==n-1:
         ans+=1
         break
       if not path[i[j]][i[j+1]]:
         break

print(ans)

Measured memory_bytes: 39920
#include<bits/stdc++.h>
using namespace std;
long long n,ans=0,a[500010];
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=3*n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+1+3*n);
	long long mid=n;
	for(int i=3*n-1;i>mid;i-=2)
		ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> vec(N);
  vector<int64_t> food(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  for(int i=0; i<N; i++){
    cin >> food.at(i);
  }
  sort(vec.begin(),vec.end());
  sort(food.rbegin(),food.rend());
  
  int64_t ok = 10000000000000000;
  int64_t ng = -1;
  while(ok - ng > 1){
    int64_t mid = (ok+ng)/2;
    int64_t cnt = 0;
    bool flag = true;
    for(int i=0; i<N; i++){
      cnt += max((int64_t)0,vec.at(i) - mid / food.at(i));
    }
    if(cnt > K){
      flag = false;
    }
    
    if(flag){
      ok = mid;
    }
    else{
      ng = mid;
    }
  }
  cout << ok << endl;
}

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

int main(){
    int N;  cin >> N;
    double ans = 0;
    for(int i=0; i<N; i++){
        double x;  string u;
        cin >> x >> u;
        if(u=="JPY") ans+=x;
        else ans += x*380000.0;
    }
    cout << fixed << setprecision(6) << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

#define SIZE 2000010
ll kaijo[SIZE];
void init() {
	kaijo[0] = 1;
	for (ll i = 1;i < SIZE;i++)kaijo[i] = (kaijo[i - 1] * i) % N;
}

ll inv(ll x) {
	ll res = 1;
	ll k = N - 2;
	ll y = x;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N*y%N) % N;
		k /= 2;
	}
	return res;
}

ll Comb(ll n, ll k) {
	if (n < 0 || k < 0 || (n - k) < 0)return 0;
	ll b = kaijo[n];
	ll c = kaijo[n - k];
	ll d = kaijo[k];
	ll cd = (c*d) % N;
	return ((b%N)*(inv(cd)) % N) % N;
}

int main(void){
    ll r1,c1,r2,c2;
    cin>>r1>>c1>>r2>>c2;
    init();
    ll ans = 0;
    for(ll i=0;i<=r2;i++){
        ans = ans+Comb(i+c2+1,c2);
        ans = ans%N;
    }
    for(ll i=0;i<r1;i++){
        ans = ans-Comb(i+c2+1,c2);
        ans = (ans+N)%N;
    }
    for(ll i=0;i<=r2;i++){
        ans = ans-Comb(i+c1,c1-1);
        ans = (ans+N)%N;
    }
    for(ll i=0;i<r1;i++){
        ans = ans+Comb(i+c1,c1-1);
        ans = ans%N;
    }
    cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 15872
import java.util.*;
class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
		int[] numbers = new int[6];
      	int check = 0;
      	for(int i = 0;i<6;i++){
        	numbers[i] = scan.nextInt();
        }
		if(numbers[4]-numbers[0] > numbers[5]){
        	check++;
        }
      	if(check > 0){
        	System.out.println(":(");
        } else {
        	System.out.println("Yay!");
        }
      	
    }
}

Measured memory_bytes: 22356
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int[] num = new int[3];
        for (int i = 0; i < 3; i++)
        {
            num[i] = cin.nextInt();
        }
        if (num[1] - num[0] == num[2] - num[1]) Console.WriteLine("YES");
        else Console.WriteLine("NO");
    }




}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13140
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	for(int i = 0; i<n; i++) cin>>a[i];
	sort(a,a+n);
	ll bob=0,alice = 0;
	for(int i = n-1; i>=0; i--)
	{
		if(i%2==(n-1)%2) alice += a[i];
		else bob += a[i];
	}
	cout<<alice-bob<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <bitset>
#include <cassert>

using namespace std;

const int k = 20009;

int p[20009];
int a[20009];
int b[20009];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> p[i];
    for (int i = 1; i <= n; ++i)
        a[i] = i * k, b[i] = (n - i + 1) * k;
    for (int i = 1; i <= n; ++i) {
        b[p[i]] += i;
    }
    for (int i = 1; i <= n; ++i)
        cout << a[i] << ' ';
    cout << endl;
    for (int i = 1; i <= n; ++i)
        cout << b[i] << ' ';
    cout << endl;
    for (int i = 2; i <= n; ++i) {
        int i1 = p[i - 1];
        int i2 = p[i];
        assert(a[i1] + b[i1] < a[i2] + b[i2]);
    }
}

Measured memory_bytes: 896
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n;cin>>n;
    int c = 0;
    REP(i,1,9){
        c += 111;
        if(n <= c){cout<<c;return 0;}
        
    }
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define MOD 1000000007

using ull = unsigned long long;

ull a[(int)3e5];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ull ans = 0;
    for (int i = 0; i <= 60; ++i) {
        ull c0 = 0, c1 = 0;
        for (int j = 0; j < n; ++j) {
            if (a[j] & ((ull)1 << i))
                c1++;
            else
                c0++;
        }
        ans += (((c0 * c1) % MOD) * (((ull)1 << i) % MOD) % MOD);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  set<pii> ans;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      ans.insert({i, j});
    }
  }
  if (n % 2 == 0) {
    for (int i = 1; i < n + 1 - i; i++) {
      ans.erase({i, n + 1 - i});
    }
  } else {
    for (int i = 1; i < n - i; i++) {
      ans.erase({i, n - i});
    }
  }
  cout << sz(ans) << "\n";
  for (auto &e : ans) {
    cout << e.fi << " " << e.se << "\n";
  }
}



Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <vector>

int main()
{
  static char s[1000000];
  scanf("%s",s);
  int n=strlen(s);
  std::vector<int> a(n+1),b(n+1);
  a[0]=0;
  for(int i=0;i<n;i++){
    a[i+1]=(s[i]=='<'?a[i]+1:0);
  }
  b[n]=0;
  for(int i=n-1;i>=0;i--){
    b[i]=(s[i]=='>'?b[i+1]+1:0);
  }
  long long ans=0ll;
  for(int i=0;i<=n;i++){
    ans+=std::max(a[i],b[i]);
  }
  printf("%lld\n",ans);
  return 0;
}


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

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)


using namespace std;
ll INF = LONG_LONG_MAX;
ll mod = 1000000000 + 7;

template <typename T, typename L>
void read(vector<T> & _data, L & _size, bool _shift) {
    _data.resize(_size + (ll)_shift);
    for (ll i = (ll)_shift; i < _size + (ll)_shift; i++)
        cin >> _data[i];
}

template <typename T, typename L>
void read(vector<vector<T>> & _data, L & _rows, L & _cols, bool _shiftRows, bool _shiftCols) {
    _data.resize(_rows + (ll)_shiftRows);
    for (ll i = 0; i < _rows + (ll)_shiftRows; i++)
        _data[i].resize(_cols + (ll)_shiftCols);
    for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++)
        for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++)
            cin >> _data[i][j];
}

template <typename T>
void write(vector<T> & _data, bool _shift) {
    for (ll i = (ll)_shift; i < _data.size(); i++)
        cout << _data[i] << " ";
    cout << endl;
}


//TODO: SOLUTION

ll n, c, m;
vll x, v, seg;

void mktree() {
    m = 1;
    while (m < n)
        m *= 2;
    seg.clear();
    seg.resize(2 * m, 0);
    ll sum = 0;
    rep(i, 0, n) {
        sum += v[i];
        seg[m + i] = sum - x[i];
    }

    for (int i = m - 1; i > 0; i--) {
        seg[i] = max(seg[2 * i], seg[2 * i + 1]);
    }
}

ll get(int l, int r) {
    l += m;
    r += m;
    ll ans = 0;
    while (l <= r) {
        if (l&1)
            ans = max(ans, seg[l++]);
        if (!(r&1))
            ans = max(ans, seg[r--]);
        l /= 2;
        r /= 2;
    }
    return ans;
}

void solve() {
    cin >> n >> c;
    x.resize(n);
    v.resize(n);

    rep(i, 0, n) {
        cin >> x[i] >> v[i];
    }

    mktree();

    ll sum = 0;
    ll ans = get(0, n - 1);
    for (int i = n - 1; i >= 0; i--) {
        sum += v[i];
        ans = max(ans, sum - 2 * (c - x[i]) + get(0, i - 1));
    }

    reverse(x.begin(), x.end());
    reverse(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
        x[i] = c - x[i];
    }

    mktree();

    ans = max(ans, get(0, n - 1));
    sum = 0;
    for (int i = n - 1; i >= 0; i--) {
        sum += v[i];
        ans = max(ans, sum - 2 * (c - x[i]) + get(0, i - 1));
    }

    cout << ans << endl;
}


int main() {

    // TODO: Set value of this variable manually
    bool _multipleTestCases = false;

    if (_multipleTestCases) {
        ll t; cin >> t;
        while (t--)
            solve();
    }
    else {
        solve();
    }

    return 0;
}

Measured memory_bytes: 6900
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=100010;
int x[N],n,L,nxt[N][20];
int main(){
	n=gi();
	for(int i=1;i<=n;i++)x[i]=gi();
	L=gi();
	for(int i=1;i<=n;i++){
		int l=i+1,r=n,ans=i;
		while(l<=r){
			int mid=(l+r)>>1;
			if(x[mid]-x[i]<=L){ans=mid;l=mid+1;}
			else r=mid-1;
		}
		nxt[i][0]=ans;
	}
	for(int j=1;j<=18;j++)
		for(int i=1;i<=n;i++)
			nxt[i][j]=nxt[nxt[i][j-1]][j-1];
	int q=gi();
	while(q--){
		int a=gi(),b=gi();if(a>b)swap(a,b);
		int ans=0;
		for(int i=18;~i;i--)
			if(nxt[a][i]<b){a=nxt[a][i];ans+=1<<i;}
		printf("%d\n",ans+1);
	}
	return 0;
}


Measured memory_bytes: 9088
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    a,b,c = LI()
    reset = set()

    for i in range(b):
        reminder = (a*i)%b
        reset.add(reminder)

    print("YES" if c in reset else "NO")

main()

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

using namespace std;

typedef long long ll;

int main(){
  ll N;
  ll A[222222];
  ll i;
  ll ans = 0;
  cin >> N;
  for(i=0;i<=N-1;i++)
    cin >> A[i];
  ll min = A[0];
  for(i=1;i<=N-1;i++){
    if(min <= A[i]){
      min = A[i];
      }
    if(min > A[i]){
      ans += min - A[i];
    }
  }
  cout << ans << endl;
}

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

int main()
{
    int r;
    cin >> r;
    cout << r * r << endl;
}

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

int main() {
        int i, j;
        int n;
        while (cin >> n) {
                if (n == 0) break;
                int sum = 0;
                vector<int> a(n);
                for (i = 0; i < n; i ++) {
                        cin >> a[i];
                        sum += a[i];
                }
                sort(a.begin(), a.end());
                sum -= a.front();
                sum -= a.back();
                cout << sum / (n - 2) << endl;
        }
        return 0;
}

Measured memory_bytes: 3136
e=(-gets.to_i..i=0).map{[]}
a=$<.map{|s|s.split.map{|v|e[v.to_i]+=[i]}
!i+=1}
e.map{|e|i=0
u={}
e.reject{|j|u[x=a[j]]=x}.map{|j|0while u[a[j]=i+=1]}}
p a.max,*a

Measured memory_bytes: 167344
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 100010;
struct Edge
{
	int to, ne;
	Edge(int _to = 0, int _ne = 0) :to(_to), ne(_ne) {}
};
vector<int> edge[maxn * 2];
int tot, ne[maxn];
int n, m, c[maxn];

void dfs(int u, int col)
{
	c[u] = col;
	for (int i = 0; i < edge[u].size(); i++) {
		int v = edge[u][i];
		if (c[v] == -1) dfs(v, !col);
		if (c[v] != !col) {
			cout << 1ll * n*(n - 1) / 2 - m << endl;
			exit(0);
		}
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	memset(c, -1, sizeof(c));
	memset(ne, -1, sizeof(ne));
	for (int i = 0; i < m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
		dfs(1, 0);
		int b = 0, w = 0;
		for (int i = 1; i <= n; i++)
			if (c[i]) ++b;
			else ++w;
			cout << 1ll * b*w - m << endl;
	return 0;
}

Measured memory_bytes: 9344
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println((a + b) %2 == 0 ? (a+b)/2 : (a+b+1)/2);
	}
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{

    lint n;
    cin >> n;
    string s;cin >> s;
    if(n==1||n%2==1){
        cout << "No"
             << "\n";
        return 0;
    }

    REP(i,n/2){
        if(s[i]!=s[i+n/2]){
            cout << "No" <<"\n";
            return 0;
        }
    }

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

Measured memory_bytes: 256
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

def sol():
    N = int(input())
    D = list(map(int, input().split()))

    ans = 0
    for d1 in D:
        for d2 in D:
            ans += d1 * d2

    for d in D:
        ans -= d * d

    print(ans // 2)


sol()

Measured memory_bytes: 3468
N,M = map(int,input().split())
if N%2:
    for i in range(M):
        print(i+1, M*2-i)
else:
    b = M//2
    a = M - b
    for i in range(a):
        print(i+1, a*2-i)
    for i in range(b):
        print(a*2+1+i, M*2+1-i)

Measured memory_bytes: 9152
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  string s;
  cin >> s;

  vll a(sz(s) + 1,0);

  ll n = sz(s) + 1;

  rep(i,n)
  {
    if(s[i] == '<')
      a[i+1] = max(a[i+1],a[i] + 1);
  }

  for(ll i = n - 1; 0 <= i; --i)
  {
    if(s[i] == '>')
      a[i] = max(a[i], a[i+1] + 1);
  }

  ll ans = 0;
  rep(i,n)
  {
    ans += a[i];
  }

  cout << ans << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 4740
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

long long GCD(long long a, long long b) {
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> x(N);
    for (int i=0; i<N; ++i) cin >> x[i], x[i] -= X;
    long long g = abs(x[0]);
    for (int i=1; i<N; ++i) g = GCD(g, abs(x[i]));
    cout << g << endl;
    return 0;
}


Measured memory_bytes: 640
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }
}

#[allow(unused_imports)]
use util::*;

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        n:i64,d:i64
    }
    let ans = roundup(n, d * 2 + 1);
    println!("{}", ans);
}


Measured memory_bytes: 4352
class UnionFind:
    def __init__(self, n):
        super().__init__()
        self.par = [-1 for i in range(n)]
        self.rank = [0 for i in range(n)]

    def root(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.par[x] > self.par[y]:
                x, y = y, x
            self.par[x] += self.par[y]
            self.par[y] = x


N, M = map(int, input().split())
union = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    union.unite(a - 1, b - 1)

print(- min(union.par))

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

int main() {
  int N;
  int64_t M;
  cin >> N >> M;
  vector<int64_t> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }
  sort(data.begin(), data.end());
  vector<int64_t> sum(N+1, 0);
  for(int i=1; i<=N; i++){
    sum.at(i)= data.at(N-i)+ sum.at(i-1);
  }

  int64_t ans= 0;
  int64_t left = data.at(0)+ data.at(0)- 1;
  int64_t right= data.at(N-1)+ data.at(N-1);
  while(right-left > 1){
    int64_t mid= left+ (right-left)/2;
    int64_t cnt_g  = 0;
    int64_t cnt_geq= 0;
    for(auto &pow:data){
      auto itr_g  = upper_bound(data.begin(), data.end(), mid- pow);
      auto itr_geq= lower_bound(data.begin(), data.end(), mid- pow);
      cnt_g  += distance(itr_g  , data.end());
      cnt_geq+= distance(itr_geq, data.end());
    }
    if(cnt_g <= M && M <= cnt_geq){
      right= mid;
      break;
    }

    if(cnt_geq < M)    right= mid;
    else if(cnt_g > M)  left= mid;
  }

  int64_t cnt= 0;
  for(auto &pow:data){
    auto itr_g= upper_bound(data.begin(), data.end(), right- pow);
    int idx= distance(itr_g, data.end());
    ans+= pow*idx + sum.at(idx);
    cnt+= idx;
  }
  ans+= right*(M-cnt);

  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
	int n;
	cin >> n;
	set<string> s;
	string mem;
	cin >> mem;
	s.insert(mem);
	rep(i, n - 1) {
		string ss;
		cin >> ss;
		if (mem[mem.size() - 1] != ss[0]) {
			cout << "No" << endl;
			return 0;
		}
		mem = ss;
		if (s.find(ss) != s.end()) {
			cout << "No" << endl;
			return 0;
		}
		s.insert(ss);
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
import sys
  
rec = 0
rhom = 0

for s in sys.stdin:
    a,b,c = [ int(x) for x in s.split(',') ]
    if c**2 == b**2 + a**2:
        rec += 1
    elif a==b and a+b > c:
        rhom += 1

print(rec)
print(rhom)


Measured memory_bytes: 5604
#include <stdio.h>

int main(void) {
int a,b;
scanf("%d",&a);
scanf("%d",&b);
if(a<b) {
	printf("a < b\n");
}else if(a>b){
	printf("a > b\n");
}else if(a==b){
	printf("a == b\n");
}

	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


const int N = (int) 2005;
vector <int> g[N];

int dfs(int v, int par, int d)
{
    int ans = 1;
    if (d == 0)
        return ans;
    for (int to : g[v])
        if (to != par)
            ans += dfs(to, v, d - 1);
    return ans;
}

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n, k;
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int ans = 0;
    for (int v = 0; v < n; v++)
    {
        ans = max(ans, dfs(v, v, k / 2));
        for (int to : g[v])
        {
            ans = max(ans, dfs(v, to, (k - 1) / 2) + dfs(to, v, (k - 1) / 2));
        }
    }
    
    printf("%d\n", n - ans);

	return 0;
}




Measured memory_bytes: 384
import sys

x, y = map(int, input().split())
s, l = min(x,y), max(x,y)

if 2*s-l<0 or (2*s-l)%3!=0:
    print(0)
    sys.exit()

r = (2*s-l)//3
n = (s+l)//3
mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, n+1):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)

def comb(n, r):
    if r<0 or r>n:
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

print(comb(n, r))


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) VL (vec)(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define eb emplace_back
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define cont const auto
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
#define PQ priority_queue
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N,C;
  cin>>N>>C;
  VL s(N),t(N),c(N);
  rep(i,N)cin>>s[i]>>t[i]>>c[i];

  VL imos(1e5+10,0);
  rep(i,N){
    imos[s[i]]++;
    imos[t[i]+1]--;
  }
  reps(i,1e5+3)imos[i]+=imos[i-1];

  int res=0;
  for(auto a:imos)chmax(res,a);
  out(min(res,C));
  
  
  
  return 0;
}



Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    string s; ll k;
    cin >> s >> k;

    int n = s.size();
    vector<ll> v;
    for (int i = 0; i < n;) {
        int len = 0;
        while (i + len < n && s[i+len] == s[i]) len++;
        v.push_back(len);
        i += len;
    }

    bool allSame = true;
    rep(i, n-1) {
        if (s[i] != s[i+1]) allSame = false;
    }

    ll ans = 0;
    if (allSame) {
        ans = (ll)n * k / 2;
    } else if (s[0] != s[n-1]) {
        for (auto &x: v) ans += x/2;
        ans *= k;
    } else {
        int m = v.size();
        rep(i, m) {
            if (i == 0 || i == m-1) {
                ans += v[i] / 2;
            } else {
                ans += (v[i] / 2) * k;
            }
        }
        ans += (k - 1) * ((v[0] + v[m-1])/2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

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

string s;
int cnt;

string a = "ACGT";

int main(){

  cin >> s;

  int n = s.size();

  rep(i,0,n) rep(j,i+1,n+1){
    bool t = true;
    rep(l,i,j) {
      bool u = false;
      rep(p,0,4) u |= (s[l] == a[p]);
      t &= u;
    }
    if(t) cnt = max(cnt,j-i);
  }

  cout << cnt << endl;

  return 0;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<char> b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        if (n != 1)
        {
            if (a[i] == 1)
            {
                if (b[i] == '0')
                {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }

        a[i]--;
    }

    for (int i = 0; i < m - 1; i++)
    {
        for (int j = i + 1; j < m; j++)
        {
            if (a[i] == a[j])
            {
                if (b[i] != b[j])
                {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }

    int nx = pow(10, n);

    for (int i = 0; i < nx; i++)
    {
        string str = to_string(i);
        if (str.size() != n) continue;

        int flg = 1;
        for (int j = 0; j < m; j++)
        {
            if (str[a[j]] != b[j]) flg = 0;
        }
        if (flg)
        {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 4116
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a * b / gcd(a, b); }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	string s;
	ll ans = 0;

	in(s);

	rep(i, 1, s.size()) {
		if (s[i] != s[i - 1]) {
			ans++;
		}
	}
	outn(ans);
	return 0;

	}
	

Measured memory_bytes: 512
// "header" {{{
#include <bits/stdc++.h>
 
using namespace std;
   
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,f,n) for(int i=f;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
  
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;
// }}}

//UnionFind{{{
struct UnionFind {
    vector<int> par;
    vector<int> siz;

    UnionFind(int n): par(n), siz(n, 1) { //�����
        for(int i = 0; i < n; i++) par[i] = i;
    }
	
    int root(int x){ //���ι�����Ƚ��
        if(par[x] == x) return x;
		else return par[x] = root(par[x]);
    }

    int size(int x){ //������
		return siz[root(x)];
	}

    bool same(int x, int y){ //���롼�פ�Ƚ��
		return root(x) == root(y);
	}

    bool unite(int x, int y){ //�Ĥʤ���
        if((x=root(x))==(y=root(y))) return false;
        if( siz[y] > siz[x] ) swap(x,y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
};
//}}}


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

    int n;
    cin >> n;

    vector<pii> x(n), y(n);

    min_heap<tuple<int, int, int> > pq;

    rep(i,n){
        cin >> x[i].first >> y[i].first;
        x[i].second = y[i].second = i;
    }

    sort(all(x));
    sort(all(y));

    rep(i,n){
        if(i - 1 >= 0){
            pq.emplace(abs(x[i].first - x[i-1].first), x[i].second, x[i-1].second);
            pq.emplace(abs(y[i].first - y[i-1].first), y[i].second, y[i-1].second);
        }
        if(i + 1 < n){
            pq.emplace(abs(x[i].first - x[i+1].first), x[i].second, x[i+1].second);
            pq.emplace(abs(y[i].first - y[i+1].first), y[i].second, y[i+1].second);
        }
    }

    UnionFind uf(n);
    int res = 0;

    while(!pq.empty()){
        int v, a, b;
        tie(v, a, b) = pq.top();
        pq.pop();
        if(uf.unite(a, b)){
            res += v;
        }
    }

    cout << res << '\n';

    return (0);
}


Measured memory_bytes: 17900
#include <bits/stdc++.h>
#define fort(i,n) for (int i = 1; i <= n; i++)
#define ll long long
#define pi pair<int,int>
#define sz size()
#define er erase
#define fr first
#define sc second
using namespace std;

ll n,m,ans;
string s,t;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> m >> s >> t;
    ll g=__gcd(n,m);
    fort(i,g)
        if (s[(i-1)*n/g]==t[(i-1)*m/g]) ++ans;
    if (ans==g) cout << n*m/g;
    else cout << -1;
}


Measured memory_bytes: 640
from collections import defaultdict
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
S = [0] * (N+1)
m = defaultdict(int)
ans = 0
for i in range(N):
    S[i+1] = (S[i] + A[i]) % M
for s in S:
    ans += m[s]
    m[s] += 1
print(ans)


Measured memory_bytes: 62576
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
typedef long long ll;

int n;
string s[110000];

int main() {
	cin >> n;
	rep(i, n) {
		char a[10];
		rep(j, 10) cin >> a[j];
		sort(a, a + 10);
		rep(j, 10) s[i] += a[j];
	}
	ll ans = 0;
	sort(s, s + n);
	string nowst;
	int nowint;
	rep(i, n) {
		if (!i) {
			nowst = s[0];
			nowint = 0;
		}
		else if (s[i] == s[i - 1]) {
			nowint++;
			ans += nowint;
		}
		else {
			nowst = s[i];
			nowint = 0;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7296
MOD = int(1e9 + 7)
n = int(input())
# es[i] := pi ** es[i]
es = [0] * 1010


def div(x):
    if x == 1: return
    for i in range(2, x + 1):
        while x % i == 0:
            es[i] += 1
            x //= i


for i in range(1, n + 1):
    div(i)

ans = 1
for i in range(1, n + 1):
    ans *= es[i] + 1

print(ans % MOD)

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[i];
  }

  sort(a.begin(),a.end());

  int idxe=n-1;
  int sum = 0;
  while(idxe >= 0){
    sum += a[idxe--];
    if(idxe < 0)
      break;
    sum -= a[idxe--];
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
// Code for A - Five Variables
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,x,y) for(ll i=x;i<(ll)(y);i++)

int main() {
  vector<int> x(5);
  REP(i, 5) {
    cin >> x[i];
  }

  REP(i, 5) {
    if ( x[i] ==0) {
      cout << i + 1 << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3568