akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<algorithm>
#include <iomanip> 
#include<vector>
#define fo(i,n) for(int i=0;i<n;i++)
#define f(i,n) for(int i=2;i<=n;i++)
#define ll long long
/*Elegizip, elegizip otken sol bir shaktar-ai
 Elendeter zamanymnyn otip bara zhatkanny-ai
Umytylmas-Umytylmas Kairan esil shaktar-ai
Zamanymnyn kolyn bulgap otip bara jatkany-ai
 kairan esil , kairan esil shaktar-ai
kolyn bulgap zamanymnyn otip bara jatkany-ai;*/
using namespace std;

int main()
{ios::sync_with_stdio(0);
ll x,y,a,b,c, ar=0,br=0,cr=0,l=0;
cin>>x>>y>>a>>b>>c;
ll aa[a];
ll bb[b];
ll cc[c];
fo(i,a){
    cin>>aa[i];
}
sort(aa,aa+a);

fo(i,b){
    cin>>bb[i];
}
sort(bb,bb+b);

fo(i,c){
    cin>>cc[i];
}
sort(cc,cc+c);
ar=a-x;
br=b-y;
cr=c-1;
ll k=0;
// ar<=a-1 || br<=b-1
while(k<x+y){
    if((aa[ar]<bb[br]  || br==b ) && ar<=a-1  ){
            if(aa[ar]<cc[cr] && cr>=0   ){
                l+=cc[cr];
                ar++;
                cr--;
            }
            else {
                l+=aa[ar];
                ar++;
            }

    }
    else if(br<=b-1) {
        if( bb[br]<cc[cr]  &&  cr>=0){

            l+=cc[cr];
            br++;
            cr--;
        }
        else {
            l+=bb[br];
            br++;

        }
        


    

    


    }


k++;

}

cout<<l;

}

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

int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll ans=0,right=0,sum=0,xorsum=0;
    rep(left,n){
        while(right<n && sum+a[right]==(xorsum^a[right])){
            sum+=a[right];
            xorsum^=a[right];
            right++;
        }
        ans+=(right-left);
        if(right==left) right++;
        else {sum-=a[left]; xorsum^=a[left];}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
#define ep 0.00001

int main()
{
	double a, b, c, d, p, q;
	double x, y;
	double det;
	
	while (cin >> a >> b >> p >> c >> d >> q) {
		det = a * d - b * c;
		x = (d * p - b * q) / det + ep;
		y = (a * q - c * p) / det + ep;
		printf("%.3f %.3f\n", x, y);
	}
	return 0;
}

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

int main () {
  int N;
  cin >> N;
  vector<int> v (N);
  for(int i = 0; i < N; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  double ans = v[0];
  for(int i = 1; i < N; i++) {
    ans = (ans + v[i]) / 2;
  }
  cout << ans << endl;
}

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

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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << a + b + c + d << endl;
}


Measured memory_bytes: 3104
# coding: utf-8
import math

num_N = int(input())

min_num = 999999
sqrt_N = math.floor(math.sqrt(num_N))

for i in range(1, sqrt_N + 1):
    if num_N % i == 0:
        len_num_A = len(str(i))
        len_num_B = len(str(int(num_N / i)))
        min_num = min(min_num, max(len_num_A, len_num_B))

print(min_num)

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

using namespace std;

int a[3];

int main(){
	for(int i = 0; i < 3; ++i) cin >> a[i];
	sort(a, a + 3);
	if(a[0] == a[1] && a[1] == 5 && a[2] == 7) cout << "YES";
	else cout << "NO";
	return 0;
	}


Measured memory_bytes: 256
#template
def inputlist(): return [int(k) for k in input().split()]
def intinput(): return int(input())
#template
A,B,Q = inputlist()
s = [0]*A
t = [0]*B
x = [0]*Q
for i in range(A):
    s[i] = intinput()
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = intinput()
s.sort()
t.sort()
ans = [0]*Q
from bisect import bisect_left
for i in range(Q):
    xa = x[i]
    s0,s1 = -1,10**18+1
    t0,t1 = -1,10**18+1
    index_s = bisect_left(s,xa)
    index_t = bisect_left(t,xa)
    if index_s == 0:
        s1 = s[0]
    if index_t == 0:
        t1 = t[0]
    if index_s == A:
        s0 = s[-1]
    if index_t == B:
        t0 = t[-1]
    if index_s != 0 and index_s != A:
        s0 = s[index_s-1]
        s1 = s[index_s]
    if index_t != 0 and index_t != B:
        t0 = t[index_t-1]
        t1 = t[index_t]
    if s0 == -1 or t1 == 10**18+1:
        d1 = 10**18+1
        d2 = 10**18+1
    if s0 != -1 and t1 != 10**18+1:
        d1 = (xa-s0)*2+(t1-xa)
        d2 = (t1-xa)*2+(xa-s0)
    if t0 == -1 or s1 == 10**18+1:
        d3 = 10**18+1
        d4 = 10**18+1
    if t0 != -1 and s1 != 10**18+1:
        d3 = (xa-t0)*2+(s1-xa)
        d4 = (s1-xa)*2+(xa-t0)
    m1 = min(s0,t0)
    M1 = max(s1,t1)
    if m1 == -1:
        d5 = 10**18+1
    if m1 != -1:
        d5 = abs(xa-m1)
    if M1 == 10**18+1:
        d6 = 10**18+1
    if M1 != 10**18+1:
        d6 = abs(xa-M1)
    ans[i] = min(d1,d2,d3,d4,d5,d6)
for i in range(Q):
    print(ans[i])


Measured memory_bytes: 20296
#include <iostream>

using namespace std;

void replace(int *array, int i1, int i2)
{
  int buf = array[i1];
  array[i1] = array[i2];
  array[i2] = buf;
}

int main()
{
  int array[3];
  cin >> array[0] >> array[1] >> array[2];

  for(int i=0; i< 2; i++){
    if(array[i] > array[i+1])
      replace(array, i, i+1);
  }
  if(array[0] > array[1])replace(array, 0, 1);

  cout << array[0] << ' ' << array[1] << ' ' << array[2] << endl;

  return 0;
}

Measured memory_bytes: 3088
def i():
	return str(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

s = i()
if len(s) == len(set(s)):
	print('yes')
else:
	print('no')


Measured memory_bytes: 2940
A=[]
l,s,t=$<.map &:chomp
l=l.to_i
a=s.size
b=t.size
2.times{
x=y=0
y+=b while (l-y)%a>0
x=l-y
A<<s*(x/a)+t*(y/b)<<t*(y/b)+s*(x/a)
s,t,a,b=t,s,b,a
}
puts A.min

Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
					  cerr << "\n\n" << "Time elapsed: " << \
					  (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
					  return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'

ll dp[1005][1005];

int main()
{
	start_routine();
	fastio;
	

    ll n,m;cin>>n>>m;
    char a[n+1][m+1];

    for(ll i=1;i<=n;i++)
    	for(ll j=1;j<=m;j++)
    		cin>>a[i][j];

    for(ll i=1;i<=n;i++)
    {
    	for(ll j=1;j<=m;j++)
    	{
    		dp[1][1]=1;
    		dp[i][j]=dp[i][j-1]+dp[i-1][j];
    		dp[i][j]%=mod;
    		if(a[i][j]=='#')
    			dp[i][j]=0;
    	}
    }

    cout<<dp[n][m];
	end_routine();
}

Measured memory_bytes: 9088
n, m = map(int, input().split())
s = [[] for i in range(n)]
for i in range(m):
    p, S = input().split()
    s[int(p) - 1] += [S]
print(sum('AC' in si for si in s), sum(si[:si.index('AC')].count('WA') if 'AC' in si else 0 for si in s))

Measured memory_bytes: 25544
m = dict()
d = dict()
n = int(input())
a = [int(i) for i in input().split()]

maxer = max(a)
for i in range(1, maxer + 1):
    m[i] = 1
    d[i] = 1

for i in a:
    if m[i] != 0 and d[i] != 0:
        d[i] = 0
        k = 2
        while True: 
            t = i * k
            if t <= maxer:
                m[t] = 0
                k += 1
            else:
                break
    elif d[i] == 0:
        m[i] = 0
        
res = 0
for i in a:
    if m[i] == 1:
        res += 1

print(res)
            

Measured memory_bytes: 146504
#include <iostream>
#include <string>

int main() {
  std::string Sd;
  std::string T;

  std::cin >> Sd;
  std::cin >> T;

  bool any_match = false;
  for (int i = Sd.size() - 1; i >= 0; i--) {
    int match = true;
    int start = i;
    int j = i;
    for (int k = T.size() - 1; k >= 0 && j >= 0; k--) {
      auto ch = Sd[j--];
      if (ch != '?' && ch != T[k]) {
        match = false;
        break;
      }
    }
    if (match && start - j == T.size()) {
      for (int k = start, l = T.size() - 1; k > j; k--) {
        Sd[k] = T[l--];
      }
      any_match = true;
      break;
    }
  }

  if (any_match) {
    for (int i = 0; i < Sd.size(); i++) {
      if (Sd[i] == '?') {
        Sd[i] = 'a';
      }
    }
    std::cout << Sd << std::endl;
  } else {
    std::cout << "UNRESTORABLE" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int a,b[22],c=0;
string s;
signed main()
{
	cin>>a;
	rep(i,a){
		cin>>b[i];
	}
	rep(i,a-2){
		if(b[i+1]!=max({b[i],b[i+1],b[i+2]})&&b[i+1]!=min({b[i],b[i+1],b[i+2]})){
			c++;
		}
	}
	cout<<c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
template <typename T>
struct segment_tree{
	int N;
	vector<T> ST;
	segment_tree(int n){
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<T>(N * 2 - 1, -INF);
	}
	T operator [](int k){
		return ST[N - 1 + k];
	}
	void update(int k, T x){
		k += N - 1;
		ST[k] = x;
		while (k > 0){
			k = (k - 1) / 2;
			ST[k] = max(ST[k * 2 + 1], ST[k * 2 + 2]);
		}
	}
	T query(int L, int R, int i, int l, int r){
		if (R <= l || r <= L){
			return -INF;
		} else if (L <= l && r <= R){
			return ST[i];
		} else {
			int m = (l + r) / 2;
			return max(query(L, R, i * 2 + 1, l, m), query(L, R, i * 2 + 2, m, r));
		}
	}
	T query(int L, int R){
		return query(L, R, 0, 0, N);
	}
	T all(){
		return ST[0];
	}
};
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  segment_tree<int> ST(300001);
  ST.update(A[0], 1);
  for (int i = 1; i < N; i++){
    int L = max(0, A[i] - K);
    int R = min(300001, A[i] + K + 1);
    ST.update(A[i], max(ST.query(L, R), 0) + 1);
  }
  cout << ST.all() << endl;
}

Measured memory_bytes: 8564
import sys, os

if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

f = lambda:list(map(int,input().split()))

def get_qsa(file_name):
    audio, size = readfile(file_name)
    headers = {
        'Connection': 'keep-alive',
        'Content-Length': str(size)
    }

    
    parameter = {
                "request_id":int(time.time()*100),
                "th":1,
                "tht":"qf492_100fps",
                "the":1.000000,
                "thst":"neural"
                }
    res = requests.post(f"http://{config['ip']}:{config['port']}", timeout=120, data=audio, headers=headers, params = parameter)
    # print(res.url)

    res_json = res.json()
    # print(res_json.keys())


    if res_json['retmsg']!="success":
        raise Exception
    

    bin_str = res_json["th"][0]["feat"]
    bin_data = base64.b64decode(bin_str)

    bin2qsa_siren(bin_data, file_name)


def solve():
    s = input()
    if int(s[-1]) in [2,4,5,7,9]:
        print("hon")
    elif int(s[-1]) in [0,1,6,8]:
        print('pon')
    else:
        print('bon')
       
    
solve()



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

using namespace std;

#define ll       long long
#define PII      pair<int, int>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);

int a[N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
    }
    int t = 1, ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] != t) {
            ans++;
        } else {
            t++;
        }
    }
    if (ans == n) ans = -1;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  if (a>=k) {
    cout << k << endl;
    return 0;
  }
  k-=a;
  if (b>=k) {
    cout << a << endl;
    return 0;
  }
  k-=b;
  if (c>=k) {
    cout << a - k << endl;
    return 0;
  } else {
    cout << a - c << endl;
    return 0;
  }

}

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

int main()
{
  int A,B;
  
  cin >> A;
  cin >> B;
  
  if(A==1){
    A=14;
  }
  if(B==1){
    B=14;
  }
  if(A>B){
    cout << "Alice" << endl;
  }
  else if(B>A){
    cout << "Bob" << endl;
  }
  else{
    cout << "Draw" << endl;
  }
  
  return 0;
}
    
        

    
    
  
  
  
  
  
  
  
  
  
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N;

int main() {
	cin >> N;
	cout << (N - 1) / 2 << endl;
}

Measured memory_bytes: 256
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>

using namespace std;

int main() {
    char M[100];
    char R[100];
    cin>>M;
    int k;
    k=strlen(M);
    int x=0;
    for(int n=0;n<k;n++){
        R[n]=M[k-1-n];
    }
    R[k]=0;
    for(int i=0;i<=(k-1)/2;i++){
        if(M[i]!=R[i]){
            x++;
        }
        else{
            x=x+0;
        }
    }
    cout<<x<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int A, B; std::cin >> A >> B;
  if(A > 9) fin(-1);
  if(B > 9) fin(-1);
  fin(A*B);
  return 0;
}


Measured memory_bytes: 256
// ankit_singhal
#define boostit ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define pii pair<ll,ll>
#define qi queue<ll>
#define mem(a,b) memset(a,b,sizeof(a))
#define print(a) cout<<a<<'\n'
#define sorted(arr) sort(arr.begin(),arr.end())
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define read(a) scanf("%d", &a)
#define f(a,n) for(ll i=a;i<n;i++)
#define in(a,n,arr) for(ll i=a;i<n;i++)cin>>arr[i];
#define in2(n,m,arr) for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cin>>arr[i][j];}
#define pown  1<<n
#define mod 1e9+7
#define mm 1e6
/*typedef tree<int, null_type, less<int>, rb_tree_tag,
 tree_order_statistics_node_update>
 ordered_set;
 typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
 tree_order_statistics_node_update>
 ordered_multiset;*/
//map<pii,ll> ma,visi;

/*vector<ll> v;
 void SieveOfEratosthenes(int n)
 {
 bool prime[n+1];
 memset(prime, true, sizeof(prime));
 
 for (int p=2; p*p<=n; p++)
 {
 if (prime[p] == true)
 {
 for (int i=p*p; i<=n; i += p)
 prime[i] = false;
 }
 }
 for (int p=2; p<=n; p++)
 if (prime[p])
 v.pb(p);
 }
*/
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
/*ll ans[(ll)mm];
ll get(ll x)
{
    //while(ans[x]!=x){x=ans[x];}
    if(ans[x]==x)return x;
    return ans[x]=get(ans[x]);
    
    //return;
}
void merge(ll a,ll b)
{
    ll temp=get(a);
    ll temp2=get(b);
    if(temp==temp2)return;
    //ans[temp]=temp2;
}*/
int main()
{
    boostit;
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll arr[n];
        for(ll i=0;i<n;i++)cin>>arr[i];
        ll count=0,ans=0;
        for(ll i=1;i<n;i++)
        {
            if(arr[i]<=arr[i-1])count++;
            else{ans=max(ans,count);count=0;}
        }
        ans=max(ans,count);
        print(ans);
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
    
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	int ans=0;
	ll n; cin>>n;
	while(n>0){
		ans+=(n%10==2);
		n/=10;
	}
	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int A ,B;
    cin >> A >> B;
    if (A >= 9 || B >= 9) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys


def main()->None:
    N = int(sys.stdin.readline())
    a = list(map(int, sys.stdin.readline().split()))
    max_a = max(a)
    # print(max_a)
    l = [0 for _ in range(max_a+2)] # 配列の初期化、固定長、位置が配列の数字で要素がカウント
    for i in a:
        l[i] += 1
    res = 0
    for i in range(0, max_a+1):
        tmp = l[i-1]+l[i]+l[i+1]
        res = max(res, tmp)
    print(res)


if __name__ == "__main__":
    main()
    


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

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

int main()
{
    int a[3][3];
    map<int, bool> m;
    REP(i, 3){
        REP(j, 3){
            cin >> a[i][j];
            m[a[i][j]] = false;
        }
    }
    int n;
    cin >> n;
    REP(i, n){
        int b;
        cin >> b;
        m[b] = true;
    }
    REP(i, 3){
        if(m[a[i][0]] && m[a[i][1]] && m[a[i][2]]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    REP(j, 3){
        if(m[a[0][j]] && m[a[1][j]] && m[a[2][j]]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    if((m[a[0][0]] && m[a[1][1]] && m[a[2][2]]) 
       || (m[a[0][2]] && m[a[1][1]] && m[a[2][0]])){
           cout << "Yes" << endl;
           return 0;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#define ll long long
const int N=1e5+10;
const ll mod=1e9+7;
int n;
ll a[N],fac=1,inv[N],ans;
ll quickpow(ll d,ll k)
{
    ll f=1;
    while(k)
    {
        if(k&1) f=f*d%mod;
        d=d*d%mod;
        k>>=1;
    }
    return f;
}
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
int main()
{
    scanf("%d",&n);
    rep(i,1,n) fac=fac*i%mod,inv[i]=quickpow(i,mod-2),scanf("%lld",a+i);
    rep(i,1,n) (inv[i]+=inv[i-1])%=mod;
    rep(i,1,n) (ans+=a[i]*(inv[i]+inv[n-i+1]-1))%=mod;
    printf("%lld\n",ans*fac%mod);
    return 0;
}

Measured memory_bytes: 3272
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] X = new int[n];
        int[] Y = new int[m];
        for (int i = 0 ; i < n ; i++) {
            X[i] = sc.nextInt();
        }
        for (int i = 0 ; i < m ; i++) {
            Y[i] = sc.nextInt();
        }
        Arrays.sort(X);
        Arrays.sort(Y);
        int xmax = X[n-1];
        int ymin = Y[0];
        if (xmax < ymin && x < xmax && y > ymin) {
            System.out.println("No War");
        } else {
            System.out.println("War");
        }

//        System.out.println("War");
//        System.out.println("No War");
    }

}

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
    string s;
    cin >> s;
    string s2 = s;
    sort(s2.begin(),s2.end(),greater<char>());
    ll n = s.size();
    ll cntb = 0, ans = 0;
    lrep(i, 0, n){
        if(s[i]=='B')cntb++;
        else{
            ans += cntb;
        }
    }
    cout << ans << endl;
}

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

int main() {
  int N;
  int A[210];
  cin>>N;
  for (int i=0;i<N;++i) cin>>A[i];

  int res=1000000000;
  for (int i=0;i<N;++i){
    int count=0;
    while(A[i]%2==0) {
      ++count;
      A[i]/=2;
    }
    if (res>count){
      res=count;
    }
  }
  cout<<res<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a[10],i,f =0,s = 0,t = 0,k,j;
    for(i=0;i<10;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<10;i++)
    {
        if(f<a[i])
        {
            f = a[i];
            k = i;
        }

    }
    for(i=0;i<10;i++)
    {
        if(i==k)continue;
        else
        {
            if(s<a[i])
            {
                s = a[i];
                j = i;
            }
        }
    }
    for(i=0;i<10;i++)
    {
        if(i==k)continue;
        if(i==j)continue;
        else
        {
            t = t>a[i]?t:a[i];
        }
    }
    printf("%d\n%d\n%d\n",f,s,t);
	return 0;
 }

Measured memory_bytes: 1820
//はじめての全方位DP
#include <iostream>
#include <cstdio>
#include <vector>
#define int long long
using namespace std;

int n;
vector<int> et[150000];
double dp[150000];		//頂点0を根としたときの部分木iについて, 頂点iからの移動回数の期待値をdp[i]とおく。
int chNum[150000];		//頂点0を根としたとき, 頂点iの子の数をchNum[i]とおく。
double ans[150000];		//頂点iを根としたとき, 頂点iからの移動回数の期待値をans[i]とおく。

double dfs(int p, int v)
{
	chNum[v] = et[v].size() - (p != -1);
	if (chNum[v] == 0) return dp[v] = 0;
	
	double ret = 0;
	for (int i = 0; i < et[v].size(); i++) {
		if (et[v][i] == p) continue;
		ret += dfs(v, et[v][i]);
	}
	ret /= chNum[v];
	return dp[v] = ret + 1;
}

void Dfs(int p, int v) {
	if (p != -1) {
		//ans[v]を求める
		double ret_p;							//vを根としたときの部分木pについて, pからの移動回数の期待値をret_pとおく。
		int childNum = (int)et[p].size() - 1;	//vを根としたときの, pの子の数
		
		if (childNum == 0) {
			ret_p = 0;
		}
		else {
			ret_p = (et[p].size() * ans[p] - dp[v] - 1.0) / childNum;
		}
		ans[v] = dp[v] * (chNum[v] / (chNum[v] + 1.0)) + (1.0 + ret_p) / (chNum[v] + 1);
	}
	for (int i = 0; i < et[v].size(); i++) {
		if (et[v][i] == p) continue;
		Dfs(v, et[v][i]);
	}
}

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		et[a].push_back(b);
		et[b].push_back(a);
	}
	dfs(-1, 0); ans[0] = dp[0];
	Dfs(-1, 0);
	
	for (i = 0; i < n; i++) {
		printf("%.14f\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 20352
using System;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Console.WriteLine(Math.Max(a[0]+a[1],Math.Max(a[0]-a[1],a[0]*a[1])));
        }
    }
}



Measured memory_bytes: 13396
//https://atcoder.jp/contests/abc166/tasks/abc166_f
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<static_cast<ll>(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
  ll N,A,B,C; cin>>N>>A>>B>>C;
  std:array<ll,3> val;
  val[0]=A,val[1]=B,val[2]=C;
  vector<char> ans;

  vector<string> sn(N);
  vector<pair<ll,ll>> swl(N);
  REP(i,N){
    auto &&s=sn.at(i);
    cin>>s;
    ll p0=s[0]-'A';
    ll p1=s[1]-'A';
    swl[i].first=p0;
    swl[i].second=p1;
  }

  REP(i,N){
    auto add_ans = [&](ll p){
      ans.push_back(sn[i][p]);
    };
    const auto [p0,p1]=swl.at(i);
    auto& v0=val[p0];
    auto& v1=val[p1];
    if(v0==1 && v1==1 && i!=N-1){
      //次を見る
      const auto [n0,n1]=swl.at(i+1);
      if(p0==n0||p0==n1){
        ++v0;
        --v1;
        add_ans(0);
      }else{
        --v0;
        ++v1;
        add_ans(1);
      }
    }else{
      if (v0>v1){
        --v0;
        ++v1;
        add_ans(1);
      }else{
        ++v0;
        --v1;
        add_ans(0);
      }
    }
    if(v0<0||v1<0){
      cout<<"No"<<endl;
      return 0;
    }
  }

  cout<<"Yes"<<endl;
  for(auto& c:ans){
    cout<<c<<endl;
  }

  return 0;
}

Measured memory_bytes: 8172
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	int min;
	for (int i = 0; i <= s.size() - t.size(); i++)
	{
		int count = 0;
		for (int j = 0; j < t.size(); j++)
			if (s[i + j] != t[j])
				count++;
		if (i == 0)
			min = count;
		else if (count < min)
			min = count;
	}
	cout << min << endl;
}

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

int F(int a, int b) {
	int i = 0;
	while (a != 0 || b != 0) {
		a /= 10;
		b /= 10;
		i++;
	}
	return i;
}

int main() {

	int64_t N;
	cin >> N;

	int ans = F(N, 1);
	for (int64_t i = 1;i <= sqrt(N);i++) {
		if (N % i == 0)
			ans = min(ans, F(i, N / i));
	}


	cout << ans;
	
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()

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; }

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

int main() {
  int n,c=0;
  cin >> n;
  
  rep(i,n){
    int x;
    cin >> x;
    if(x!=i+1)c++;
  }
  
  if(c<3) cout << "YES" <<endl;
  else cout << "NO" <<endl;
   
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
struct UnionFind{
vector<int> par,depth;
vector<ll> Size;
UnionFind(int n){
par.resize(n); depth.resize(n); Size.resize(n);
for(int i=0; i<n; i++){
par[i]=i;
depth[i]=0;
Size[i]=1;
}
}
int find(int x){
if(par[x]==x){
return x;
}
else{
return par[x]=find(par[x]);
}
}
bool same(int x, int y){
return find(x)==find(y);
}
void unite(int x, int y){
x=find(x); y=find(y);
if(x==y) return;
if(depth[x]<depth[y]) swap(x,y);
if(depth[x]==depth[y]) depth[x]++;
par[y]=x;
Size[x]+=Size[y];
}
ll size(int x){
    return Size[find(x)];
}
};
int main(){
    ll n,m;cin >> n >> m;
    vector<int> a(m),b(m);
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
    }
    vector<ll> ans(m+1);
    ans[0]=n*(n-1)/2;
    int id=0;
    UnionFind uf(100050);
    for(int i=m-1;i>=0;i--){
        if(uf.same(a[i],b[i])){
            ans[id+1]=ans[id];
        }
        else{
            ans[id+1]=ans[id]-(ll)(uf.size(a[i]))*uf.size(b[i]);
            uf.unite(a[i],b[i]);
        }
        id++;
    }
    for(int i=m-1;i>=0;i--) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 4480
using System; 
using System.Text; 
using System.Collections.Generic;
using System.Linq; 
using E = System.Linq.Enumerable; 

class Program { 
     static void Main(string[] args) {
     //入力を受け取る
     var N = int.Parse(Console.ReadLine());
     var X = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
     int[] Y = new int[N];
     Array.Copy(X, Y, X.Length);
     Array.Sort(X);
     
     for(int i = 0;i < N;i++){
         var y = Y[i];
         //Console.WriteLine(y);
         if(y <= X[N/2-1]){
             //N/2+1番目を出力
             Console.WriteLine(X[N/2]);
         }else{
              //N/2番目を出力
            Console.WriteLine(X[N/2-1]);
         }
     }
     }
     }


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

int a[10];

ll gcd(ll m,ll n){
  if(m==0 || n==0) return 0;
  while(m!=n){
    if(m>n) m=m-n;
    else n=n-m;
  }
  return m;
}

ll lcm(ll a,ll b){
  if(a==0 || b==0) return 0;
  return (a/gcd(a,b))*b;
}

ll lcmnum(int n){
  int p=a[0];
  for(int i=1;i<n;i++){
    p=lcm(p,a[i]);
  }
  return p;
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  cout<<lcmnum(n)<<endl;
  return 0;
}



Measured memory_bytes: 3124
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n;
  	cin >> n;
  	vi a(n);
  	rep(i,n) cin >> a[i];
  	sort(all(a));
  	
  	rep(i,a.size()-1) {
      	if(a[i] == a[i+1]){ 
          	cout << "NO" << endl;
          	return;
        }
    }
  	cout << "YES" << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();
 
using namespace std;
const int N=2e5+1, mod=998244353;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int y;
	string s;
	cin>>y>>s;
	for(auto &x:s){
		x=char( 'A' + ((x-'A')+y)%26 );
	}
	cout<<s;
	
    yogeshk972();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
using namespace std;

//ABC135 B
int main() {
	int n;
	cin >> n;
	int A[100];
	for (int i=0; i<n; i++){
		cin >> A[i];
	}

	int cnt = 0;
	for (int i=0; i<n; i++) {
		if (A[i] != i+1) {
			cnt++;
		}
	}
	if (cnt == 2 || cnt == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

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

const int END = -1;
struct StNod
{
  int m_nKey;
  int m_nParnt;
  int m_nLeft;
  int m_nRigt;

  StNod() :
    m_nKey(END), m_nParnt(END), m_nLeft(END), m_nRigt(END)
  { }
};

void fnInput(vector<StNod> &rvoNod)
{
  StNod oNod;
  int nMaxSiz;

  cin >> nMaxSiz;
  rvoNod.resize(nMaxSiz, oNod);

  for (int i = 0; i < nMaxSiz; i++)
  {
    int nKey, nLeft, nRigt;
    cin >> nKey >> nLeft >> nRigt;

    rvoNod[nKey].m_nKey  = nKey;
    rvoNod[nKey].m_nLeft = nLeft;
    rvoNod[nKey].m_nRigt = nRigt;
    if (nLeft != END)  rvoNod[nLeft].m_nParnt = nKey;
    if (nRigt != END)  rvoNod[nRigt].m_nParnt = nKey;
  }
}

void fnPreOrder(const vector<StNod> &cnrvoNod, int nx)
{
  if (nx == END)  return;

  cout << " " << nx;
  fnPreOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  fnPreOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);
}

void fnInOrder(const vector<StNod> &cnrvoNod, int nx)
{
  if (nx == END)  return;

  fnInOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  cout << " " << nx;
  fnInOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);
}

void fnPostOrder(const vector<StNod> &cnrvoNod, int nx)
{
  if (nx == END)  return;

  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nLeft);
  fnPostOrder(cnrvoNod, cnrvoNod[nx].m_nRigt);
  cout << " " << nx;
}

void fnTreeWalk(const vector<StNod> &cnrvoNod)
{
  int nx = 0;
  while (cnrvoNod[nx].m_nParnt != END)
    nx = cnrvoNod[nx].m_nParnt;

  cout << "Preorder" << endl;
  fnPreOrder(cnrvoNod, nx);
  cout << endl;

  cout << "Inorder" << endl;
  fnInOrder(cnrvoNod, nx);
  cout << endl;

  cout << "Postorder" << endl;
  fnPostOrder(cnrvoNod, nx);
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<StNod> voNod;

  fnInput(voNod);
  fnTreeWalk(voNod);
  return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N,M;

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

    ll b=1;

    for(int i=0;i<M;i++)b*=2;
    
    ll ans=(100*N+1800*M)*b;

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

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


int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> memo(n + 1, make_pair(1, 0));
  memo[1].second = 1;
  rep (i, m) {
    int x, y;
    cin >> x >> y;

    if (memo[x].second == 1) {
      memo[y].second = 1;
    }
    memo[x].first--;
    memo[y].first++;
    if (memo[x].first == 0) memo[x].second = 0;
  }
  
  int ans = 0;
  for (int i = 1; i <= n; i++) 
    if (memo[i].second) ans++;

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

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		try {
			String[] alpha = { "a", "b", "c", "d", "e", "f", "g", "h", "i",
					"j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u",
					"v", "w", "x", "y", "z" };
			int[] alpha_int = new int[26];

			BufferedReader stdReader = new BufferedReader(
					new InputStreamReader(System.in));
			String line;
			while ((line = stdReader.readLine()) != null) {

				int length1 = 0;
				int length2 = 0;


					String s = line;
					length1 = s.length();
					for (int j = 0; j < 26; j++) {
						s = s.toLowerCase();
						s = s.replaceAll(alpha[j], "");
						length2 = s.length();
						alpha_int[j] += length1 - length2;
						s = line;
					}

				

			}
			
			for (int i = 0; i < 26; i++) {
				System.out.print(alpha[i]);
				System.out.print(" : ");
				System.out.println(alpha_int[i]);
			}
			
		} catch (Exception e) {
			e.getStackTrace();
			System.exit(0);
		}
	}
}

Measured memory_bytes: 28116
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


#define debug 1

int n, m,k;
string s,t;

int main() {
	cin>>n;
	VI p(n);//右(左)向きに自分より大きいもののindex
	vector<vector<long long>> migi(n, vector<long long>(2,n)), hidari(n, vector<long long>(2,-1));//hidariはindex=n-1-x
	long long ans = 0;
	rep(i, n)cin >> p[i];
	for (int i = 0; i < n; i++)
	{
		int iter = i-1;
		if (i) {
			if (p[i - 1] < p[i]) {
				iter = hidari[i-1][0];
			}
		}
		bool flag = false;
		while (iter >= 0) {
			if (p[iter] > p[i] && flag) {
				hidari[i][1] = iter;
				break;
			}
			else if(p[iter]>p[i]&&!flag){
				flag=true;
				hidari[i][0] = iter;
			}
			iter--;
		}
	}
	for (int i = n-1; i >=0; i--)
	{
		int iter = i+1;
		if (n-1-i) {
			if (p[i+1] < p[i]) {
				iter = migi[i + 1][0];
			}
		}
		bool flag = false;
		while (iter <n) {
			if (p[iter] > p[i] && flag) {
				migi[i][1] = iter;
				break;
			}
			else if (p[iter] > p[i] && !flag) {
				flag = true;
				migi[i][0] = iter;
			}
			iter++;
		}
	}
	for (int i = 0; i < n; i++)
	{
		ans += p[i] * (((hidari[i][0] - hidari[i][1])*(migi[i][0] - i)) + ((i - hidari[i][0])*(migi[i][1] - migi[i][0])));
	}
	cout <<ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    for (auto& i:a) cin >> i;
    int sum = accumulate(a.begin(),a.end(),0);
    for (int j=0;j<n;j++) {
        b[j] = abs(sum-n*a[j]);
    }
    auto pos = min_element(b.begin(),b.end());
    cout << distance(b.begin(),pos) << endl;
    return 0;
}

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

int n,m,ma[1001],mb[1001];
long long fw[101][101],mc[1001];

int main(){
	cin>>n>>m;
	int mm=m;
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			fw[i][j]=1000000;
			if(i==j){
				fw[i][j]=0;
			}
		}
	}
	for(int i=1;i<=m;i++){
		cin>>ma[i]>>mb[i]>>mc[i];
		fw[ma[i]][mb[i]]=mc[i];
		fw[mb[i]][ma[i]]=mc[i];
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(fw[i][k]+fw[k][j]<fw[i][j]){
					fw[i][j]=fw[i][k]+fw[k][j];
				}
			}
		}
	}
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(fw[j][ma[i]]+mc[i]==fw[j][mb[i]]){
				mm--;
				break;
			}
		}
	}
	cout<<mm<<endl;
}

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

int main() {
    int N;
    cin>>N;
    vector<int>arr(N);
    for(int i=0;i<N;i++)
        cin>>arr[i];
    int maxi=0;
    int total=0;
    for(int i=1;i<N;i++){
        if(arr[i]<=arr[i-1]){
            total++;
        }
        else{
            if(total>maxi)
                maxi=total;
            total=0;    
        }
    }
    if(total>maxi)
        maxi=total;
    cout<<maxi;
	return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"strings"
)

func max(x, y int) int {
	if x >= y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x >= y {
		return y
	}
	return x
}

func main() {
	ans := []string{}
	for {
		var x, y int
		fmt.Scan(&x, &y)
		if x+y == 0 {
			break
		}
		ans = append(ans, fmt.Sprintf("%d %d", min(x, y), max(x, y)))
	}
	fmt.Println(strings.Join(ans, "\n"))
}



Measured memory_bytes: 1500
n=int(input())
a=input()
b=input()
c=input()
ct=0
for i in range(n):
  if a[i]==b[i] and b[i]==c[i]:ct+=0
  elif a[i]==b[i] or b[i]==c[i] or c[i]==a[i]:ct+=1
  else:ct+=2
print(ct)

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

import math

def main():
    a,b,n = map(int, input().split())

    if b > n:
        print(math.floor(a*n/b) - a*math.floor(n/b))

    else:
        print(math.floor(a*(b-1)/b) - a*math.floor((b-1)/b))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  for(int i=0;i<=B;i++){
    if((i*A)%B==C){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# hello worldと表示する
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors
#print(make_divisors(10))
n=I()
lis=sorted(LI())
u=make_divisors(lis[0])

for j in range(len(u)):
    br=u[j]
    count=0
    #print(br)
    for i in range(n):
        if lis[i]%br!=0:
            count+=1
    if count<=1:
        ans1=br
        break
#print(ans1)

v=make_divisors(lis[1])

for j in range(len(v)):
    bre=v[j]
    counti=0
    #print(bre)
    for i in range(n):
        if lis[i]%bre!=0:
            counti+=1
    if counti<=1:
        ans2=bre
        break
#print(ans2)
print(max(ans1,ans2))

Measured memory_bytes: 59632
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 2e6 + 7;
int n = 0;
char s[10];
int h[MAXN];
void maxHeapify(int cur) {
	int l = (cur << 1) + 1, r = l + 1, mx = cur;
	if (l < n && h[l] > h[mx]) mx = l;
	if (r < n && h[r] > h[mx]) mx = r;
	if (mx != cur) {
		swap (h[cur], h[mx]);
		maxHeapify(mx);
	}
}
int main() {
    while (1) {
    	scanf("%s", s);
    	if (s[0] == 'i') {
    		scanf("%d", &h[n++]);
    		for (int i = n - 1; i && h[((i - 1) >> 1)] < h[i]; i = (i - 1) >> 1) {
    			swap(h[((i - 1) >> 1)], h[i]);
			}
		}
		else if (s[1] == 'x') {
			printf("%d\n", h[0]);
			h[0] = h[--n];
			maxHeapify(0);
		}
		else return 0;
	}
}


Measured memory_bytes: 6496
#include <iostream>
typedef long long ll;
using namespace std;
string s;

int numofgreater(int index) {
    int num=0;
    for (int i = index; i < s.size(); i++) {
        if (s[i]=='>') num++;
        else break;
    }
    return num;
}

int main() {

    cin >> s;
    int size = s.size();
    int ans[size+1];
    for (int i = 0; i <= size; i++) {
        ans[i]=0;
    }
    for (int i = 0; i < size; i++) {
        if (s[i]=='<') {
            ans[i+1]=ans[i]+1;
        } else if (s[i]=='>') {
            int consecutive = numofgreater(i);
            if (ans[i]<consecutive) {
                ans[i]=consecutive;
            }
            for (int j=consecutive-1; j>0; j--) {
                ans[i+1]=j;
                i++;

            }
        }
    }
    ll res=0;
    for (int i = 0; i <= size; i++) {
        res+=ans[i];
    }
    cout << res << endl;

}

Measured memory_bytes: 2820
mod2019=[0]*2019
mod2019[0]=1
t=input()
n=len(t)
s=[]
for i in range(n):
  s.append(int(t[i]))
x=1
y=0
for i in reversed(range(n)):
  y+=s[i]*x
  mod2019[y%2019]+=1
  x=(x*10)%2019
ans=0
for i in range(2019):
  ans+=mod2019[i]*(mod2019[i]-1)
print(ans//2)

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

using namespace std;
int n, w[201000], p[201000];
set<int>Set;
long long res;
int main(){
    int i, a ,b;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&w[i]);
        p[w[i]] = i;
    }
    Set.insert(0);
    Set.insert(n+1);
    for(i=1;i<=n;i++){
        set<int>::iterator it;
        it = Set.lower_bound(p[i]);
        b = *it;
        it--;
        a = *it;
        res += 1ll * (p[i]-a)*(b-p[i])*i;
        Set.insert(p[i]);
    }
    printf("%lld\n",res);
}

Measured memory_bytes: 11136
n,m=gets.split.map &:to_i
a=[]
b=[]
c=[]
d=[]
n.times{x,y,z=gets.split.map &:to_i
a<<x+y+z
b<<x+y-z
c<<x-y+z
d<<x-y-z
}
a.sort!;b.sort!;c.sort!;d.sort!
s=0
t=0
u=0
v=0
for k in 0...m
  s+=a[k]
  t+=b[k]
  u+=c[k]
  v+=d[k]
end
i=[s.abs,t.abs,u.abs,v.abs].max
s=0
t=0
u=0
v=0
for k in 1..m
  s+=a[-k]
  t+=b[-k]
  u+=c[-k]
  v+=d[-k]
end

p [s.abs,t.abs,u.abs,v.abs,i].max



Measured memory_bytes: 1916
#include<iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  //整数の時はint
  int n,k,d,a,sum=0;;
  int ans[100];
  for(int i=0;i<100;i++){
    ans[i]=0;}
  //文字の時はstring
  // int a;


  cin>>n>>k;
  for(int i=0;i<k;i++){
    cin>>d;
    for(int j=0;j<d;j++){
      cin>>a;
      ans[a-1]++;}
  }
  for(int i=0;i<n;i++){
    if(ans[i]==0)
      sum++;
  }
  cout<<sum<<endl;
      
     
  return 0;
}

Measured memory_bytes: 3624
import std.bigint;
import std.conv;
import std.stdio;
import std.string;

void main() {
	int n = to!int(chomp(readln()));
	BigInt fact = BigInt(1);
	foreach(i; 2..n+2) {
		fact *= i;
	}

	writeln(fact + 2);
	foreach(i; 0..n) {
		writeln(i + 2);
	}
}

Measured memory_bytes: 2140
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	cout << fixed << setprecision(18);

	ll h, w, n;
	cin >> h >> w >> n;

	vector<P> a;
	ll tmp;
	rep(i, n) {
		cin >> tmp;
		a.push_back(P(tmp, i + 1));
	}

	ll tile[100][100];
	memset(tile, 0, sizeof(tile));

	sort(a.begin(), a.end(), greater<>());

	ll x, y;
	x = y = 0;
	rep(i, n)
	{
		rep(j, a[i].first)
		{
			tile[x][y] = a[i].second;
			if (y % 2 == 0)
			{
				if (x == w - 1) {
					if (y == h - 1)
						break;
					else
						y++;
				}
				else
					x++;
			}
			else if (y % 2 == 1)
			{
				if (x == 0) {
					if (y == h - 1)
						break;
					else
						y++;
				}
				else
					x--;
			}
		}
	}

	rep(j, h)
	{
		rep(i, w)
		{
			cout << tile[i][j];
			if (i != w - 1)
				cout << " ";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 640