akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,x,y,i,j,w,cur,res;
	string s;
	cin >> s >> x >> y;
	set<int> px1={},px2={},py1={},py2={},p0={};
	py1.insert(0);
	
	s.push_back('T');
	for(j=0; j<s.size(); j++){
		if(s[j]=='T'){
			w=1;
			px1.insert(j);
			cur=j;
			break;
		}
	}
	
	auto itr=px1.begin();
	res=0;
	for(i=cur+1; i<s.size(); i++){
		if(s[i]=='T'){
			if(w==1){
				itr=py1.begin();
				while(itr!=py1.end()){
					py2.insert(*itr+res);
					py2.insert(*itr-res);
					itr++; 
				}
				py1=py2; py2=p0;
			}else{
				itr=px1.begin();
				while(itr!=px1.end()){
					px2.insert(*itr+res);
					px2.insert(*itr-res);
					itr++; 
				}
				px1=px2; px2=p0;
			}
			res=0;
			w=(w+1)%2;
		}else{
			res++;
		}
	}
	
	/*
	itr=px1.begin();
	while(itr!=px1.end()){
		cout << *itr << ' ';
		itr++;
	}
	cout << endl;
	itr=py1.begin();
	while(itr!=py1.end()){
		cout << *itr << ' ';
		itr++;
	}
	cout << endl;
	*/
	if(px1.count(x) && py1.count(y)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 768
import java.util.ArrayList;
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		ArrayList<Integer> Cases = new ArrayList<>();
		Scanner scan = new Scanner(System.in);
		while(true) 
		{
			int x = scan.nextInt();
			if(x==0)
			{
				break;
			}
			Cases.add(x);
		}
		for(int i=0;i<Cases.size();i++)
		{
			System.out.println(String.format("Case %s: %s",i+1,Cases.get(i)));
		}
	}
}



Measured memory_bytes: 56236
#include<bits/stdc++.h>
#define fori(a,b,c) for(int a=b;a<(int)c;a++)
typedef long long ll;
using namespace std;
ll n,m,k,arr[100005],ans,x; 
int main(){
	cin >> n >> m;
	fori(q,0,n){
		cin >> k;
		fori(i,0,k){
			cin >> x;
			arr[x]++;
		}
	}
	fori(i,0,m){
		if(arr[i+1]==n)
			ans++;
	}
	cout << ans;
}	



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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

int k;
string s;

int main()
{
    _FastIO;

    cin >> k;
    int a = k / 2;
    int b = a + k % 2;
    cout << a * b << endl;

    return 0;
}


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

vector<int> divisor(int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

int n;
vector<int> a;

int main() {
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> count(1000001, 0);
    for (auto e : a) {
        count[e]++;
    }
    int ans = 0;
    for (auto e : a) {
        auto div = divisor(e);
        bool sure = true;
        for (auto d : div) {
            int ok = 0;
            if (d == e) {
                ok = 1;
            }
            if (count[d] > ok) {
                sure = false;
                break;
            }
        }
        if (sure) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8012
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define rept(i,x) for(int i = linkk[x];i;i = e[i].n)
#define P pair<int,int>
#define Pil pair<int,ll>
#define Pli pair<ll,int>
#define Pll pair<ll,ll>
#define pb push_back 
#define pc putchar
#define mp make_pair
#define file(k) memset(k,0,sizeof(k))
#define ll long long
int rd()
{
    int sum = 0;char c = getchar();bool flag = true;
    while(c < '0' || c > '9') {if(c == '-') flag = false;c = getchar();}
    while(c >= '0' && c <= '9') sum = sum * 10 + c - 48,c = getchar();
    if(flag) return sum;
    else return -sum;
}
int main() 
{
    int n,k;
    k=  rd();
    if(k<=500)
    {
        n = k;
        printf("%d\n",n);
        rep(i,1,n)
        {
            rep(j,1,n) printf("%d ",j);
            printf("\n");
        }
    }
    else
    {
        n=500;printf("%d\n",n);
        rep(i,1,n)
        {
            rep(j,1,n)
            {
                int x=(i+j)%n+1+(i&1?n:0);
                printf("%d ",x<=k?x:x-n);
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
using graph = vector<vector<ll>>;

int main() {
	
	ll s, w;
	cin >> s >> w;
	if (s <= w) {
		cout << "unsafe" << endl;
	}
	else {
		cout << "safe" << endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

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


Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int main()
{
	int a = { 0 };
	char op;
	int b;
	int result;
	while (1){
		cin >> a >> op >> b;
		if (op == '+'){ result = a + b; }
		else if (op == '-'){ result = a - b; }
		else if (op == '*'){ result = a*b; }
		else if (op == '/'){ result = a / b; }
		else if (op == '?'){ return 0; }
		cout << result<<endl;
	}
}

Measured memory_bytes: 3096
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  return ~~Math.ceil((intShift()+intShift())/2);
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
20 5
`);

Measured memory_bytes: 7372
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::vector<i64> a;
  tools::read(a, 3 * N);

  std::sort(a.begin(), a.end(), std::greater<i64>());
  i64 answer = 0;
  for (i64 i = 1; i < 2 * N; i += 2) {
    answer += a[i];
  }

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

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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;



int main()
{
	string str, der, p, pre;
	int q, a, b, len;

	cin >> str >> q;
	len = str.length();

	rep(i, q) {
		cin >> der;

		if (der == "replace") {
			pre = str;
			str = "";
			cin >> a >> b >> p;
			repc(j, 0, a - 1) str += pre[j];
			str += p;
			repc(j, b + 1, len - 1) str += pre[j];
		}
		else if (der == "reverse") {
			pre = str;
			str = "";
			cin >> a >> b;
			repc(j, 0, a - 1) str += pre[j];
			rrepc(j, b, a) str += pre[j];
			repc(j, b + 1, len - 1) str += pre[j];
		}
		else {
			cin >> a >> b;
			repc(j, a, b) cout << str[j];
			cout << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3164
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  int N; cin>>N;
  vector<int> sa(N);
  rep(i,N)
  {
    cin>>sa.at(i);
  }
  rep(i,N)
  {
    ll b; cin>>b;
    sa.at(i)-=b;
  }
  /*
  rep(i,N)
  {
    if(i!=0) {cout<<" ";}
    cout<<sa.at(i);
  }
  cout<<endl;
  */
  sort(sa.begin(),sa.end());
  ll hoge=0;
  int ans=0;
  rep(i,N)
  {
    if(sa.at(i)>=0) {break;}
    hoge+=sa.at(i);
    ans++;
  }
  hoge*=-1;
  reverse(sa.begin(),sa.end());
  rep(i,N)
  {
    if(hoge<=0) {break;}
    hoge-=sa.at(i);
    ans++;
  }
  if(hoge>0) {cout<<-1<<endl; return 0;}
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

typedef long long ll;
typedef pair<ll,ll> P;

#define MOD 1000000007

long long totient(long long a) {
	ll ret = a;
	for(int i = 2;i * i <= a;i++){
		if(a % i == 0){
			ret = ret * (i - 1) / i;
			while(a % i == 0)a /= i;
		}
	}
	if(a > 1)ret = ret * (a - 1) / a;
	return ret;
}

// a / b (mod p) b と p は互いに素
// O(sqrt(p))かかるので注意
long long totient_div(long long a, long long b, long long p) {
	long long ret = a;
	long long tp = totient(p) - 1;
	long long c = b;
	for(int i = 0;i <= 60;i++){
		if(tp & (1LL << i))ret = (ret * c) % p;
		c = (c * c) % p;
	}
	return ret;
}

//a^b % MOD
long long modpow(ll a,ll b){
	long long ret = 1;
	long long c = a;
	for(int i = 0;i <= 60;i++){
		if(b & (1LL << i))ret = (ret * c) % MOD;
		c = (c * c) % MOD;
	}
	return ret;
}

//ａをbで割る
long long mod_div(long long a,long long b){
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 333333
vector<long long> kaijo(MAX_K);
long long combination(long long n, long long r){
    if(n < r || n < 0 || r < 0)
        return 0;
	ll ue = 1;
	ll sita = 1;
	REP(i, r)ue = ue * (n - i) % MOD;
	REP(i, r)sita = sita * (i + 1) % MOD;
	return mod_div(ue, sita);
}

void modAdd(ll &a, ll b){
	a += b;
	a %= MOD;
}


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

	ll n, m, k;cin >> n >> m >> k;
	ll ans = 0;
	ll kake = combination((n * m - 2) % MOD, k - 2);

	REP(i, n){
		ll a, b;
		if(i == 0)a = m * (m - 1) % MOD;
		else a = m * m % MOD;
		b = n - i;
		modAdd(ans, (a * b % MOD) * i % MOD);
	}
	REP(i, m){
		ll a, b;
		if(i == 0)a = n * (n - 1) % MOD;
		else a = n * n % MOD;
		b = m - i;
		modAdd(ans, (a * b % MOD) * i % MOD);
	}

	cout << ans * kake % MOD << endl;

	return 0;
}


Measured memory_bytes: 2816
#include <stdio.h>
#include <string.h>
int main(void){
    
    int i,n,max=0,x=0;
    char s[101];
    
    scanf("%d",&n);
    scanf("%s",s);
    for(i=0;i<n;i++){
        if(s[i]-'I'==0){
            x++;
        }
        else x--;
        if(x>max){
            max=x;
        }
    }
    
    printf("%d\n",max);
}


Measured memory_bytes: 128
# coding: utf-8
# Your code here!
# AtCoder Beginner Contest 167
N,M,X=map(int,input().split(" "))
array=[]
_INF_ = 1001001001
ans = _INF_
for i in range(N):
     H = input().rstrip()
     array.append(H.split(" "))
# print(array)

for i in range(1<<N): #2の3条になる(1をNビット右にシフトするから)
    cost = 0
    understand = [0 for un in range(M)]
    # print(understand)
    for j in range(N):
        if(((i>>j)&1)): #a&b : AND:論理積 100*010 = 000, 100+100=100,シフトしたあと１との論理積を取ることで必要なビット田だけ取り出せる
            ar = array[j][0]
            cost+=int(ar)
            for un in range(M):
                a1 = array[j][un+1]
                understand[un]+=int(a1)
        ok = True
    for un in range(M):
        if understand[un]<X:
            ok = False
    if ok:
        ans = min(ans, cost)
        # print(understand)
        # print(cost)
if(ans == _INF_):
    print(-1)
else:
    print(ans)
        

Measured memory_bytes: 9260
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2);
  return x*POW(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,k,a[120000],c;
  cin >> n >> k;
  rep(i,n)cin >> a[i];
  c=a[0];
  SORT(a,n);
  rep(i,n)c=gcd(a[i],c);
  if(k%c==0&&k<=a[0])printf("POSSIBLE");
  else printf("IMPOSSIBLE");
}

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int a[3];

int main() {
    rep(i,3) cin >> a[i];
    sort(a, a+3);
    int ans = 0;
    ans = a[2]-a[1];
    a[0] += (a[2]-a[1]);
    ans += (a[2]-a[0])/2;
    if ((a[2]-a[0])%2 == 1) ans += 2;
    cout << ans << endl;
}
































Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N
#define LL long long
char s[15];
map <string,int> mp;
int main() {
	int n;
	cin >> n;
	LL ans = 0;
	for(int i=1; i<=n; i++) {
		scanf("%s",s+1);
		int l = strlen(s+1);
		sort(s+1,s+l+1);
		ans += mp[s+1];
		mp[s+1] ++;
	}
	cout<<ans;
	return 0;
}


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

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> v(m);
  for(int i=0; i < m; i++) cin >> v[i];
  sort(v.begin(), v.end());

  int count_a = 0;
  for(int i=0; i < m; i++) {
    if(x <= v[i]) break;
    count_a++;
  }
  int count_b = 0;
  for(int i=m-1; 0 <= i; i--) {
    if(x >= v[i]) break;
    count_b++;
  }
  cout << min(count_a, count_b) << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    int n, p; cin >> n >> p;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    long long dp[n+1][2];
    dp[0][0] = 1; dp[0][1] = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] % 2) {
            dp[i+1][0] = dp[i][0] + dp[i][1];
            dp[i+1][1] = dp[i][1] + dp[i][0];
        } else {
            dp[i+1][0] = dp[i][0] + dp[i][0];
            dp[i+1][1] = dp[i][1] + dp[i][1];
        }
    }
    cout << dp[n][p] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	
		int dx = tx - sx;
		int dy = ty - sy;
		int countU = 0;
		int countD = 0;
		int countL = 0;
		int countR = 0;
		if (dy < 0) {
			countD = abs(dy);
		}
		else {
			countU = dy;
		}
		if (dx < 0) {
			countL = abs(dx);
		}
		else {
			countR = dx;
		}
		//往復１
		int j = 0;
		while (j < 2) {
			if (j > 0) {
				dy *= -1;
				dx *= -1;
			}
			if (dy < 0) {
				rep(i, abs(dy)) {
					cout << "D";
				}
			}
			else {
				rep(i, dy) {
					cout << "U";
				}
			}
			if (dx < 0) {
				rep(i, abs(dx)) {
					cout << "L";
				}
			}
			else {
				rep(i, dx) {
					cout << "R";
				}
			}
			j++;
		}
		
		//往復2
		int i = 0;
		while (i < 2) {
			if (i > 0) {
				swap(countR, countL);
				swap(countD, countU);
			}
			if (countU>0) {
				cout << "D" ;
			}
			else {
				cout << "U";
			}
			
			if (countR > 0) {
				rep(i, countR + 1) {
					cout << "R";
				}
			}
			else if(countL>0) {
				rep(i, countL + 1) {
					cout << "L";
				}
			}
			if (countU > 0) {
				rep(i, countU + 1) {
					cout << "U";
				}
			}
			else if(countD>0) {
				rep(i, countD + 1) {
					cout << "D";
				}
			}
			if (countR>0) {
				cout << "L";
			}
			else {
				cout << "R";
			}
			i++;
		}
	
}


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

int main(){

    double r, pi = 3.14159265359;
    cin >> r;
    cout << fixed;
    cout << setprecision(8)  << r * r * pi << " " << 2 * r * pi << "\n";

    return 0;  
}


Measured memory_bytes: 3260
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 1e6 + 10, mod = 1e9 + 7;
int n, m, x[N], y[N];
int main() {
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%d",x + i);
	rep(i,1,m) scanf("%d",y + i);
	int s1 = 0, s2 = 0;
	rep(i,1,n - 1) s1 = (s1 + 1LL * (x[i + 1] - x[i]) * (n - i) % mod * i) % mod;
	rep(i,1,m - 1) s2 = (s2 + 1LL * (y[i + 1] - y[i]) * (m - i) % mod * i) % mod;
	printf("%lld\n",1LL * s1 * s2 % mod);
	return 0;
}


Measured memory_bytes: 4736
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int N,A[100005],s=0;
int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)scanf("%d",&A[i]);
	for(int i=0;i<=N;i++)
	{
		s=A[s]-1;
		if(s==1)
		{
			printf("%d\n",i+1);
			return 0;
		}
	}
	puts("-1");
	return 0;
}


Measured memory_bytes: 640
N=int(input())
S=input()

wsum=[0]*N
if S[0]=='W':
    wsum[0]=1
else:
    wsum[0]=0    
for i in range(1,N):
    if S[i]=='W':
        wsum[i]=wsum[i-1]+1
    else:
        wsum[i]=wsum[i-1]

SR=S[::-1]
esum=[0]*N
if SR[0]=='E':
    esum[0]=1
else:
    esum[0]=0
for i in range(1,N):
    if SR[i]=='E':
        esum[i]=esum[i-1]+1
    else:
        esum[i]=esum[i-1]
esum=esum[::-1]

ans=N
for i in range(N):
    ans=min(ans,wsum[i]+esum[i]-1)
print(ans)

Measured memory_bytes: 20156
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)

typedef long long ll;

const int INF = 1<<29;

ll N, K;
vector <int> v;

//ある最大積載量の時にそれがokか否か判定する関数
bool check(ll c) {
    //現在の積載量,トラックを何回交代したか
    ll tmp = 0LL, cnt = K-1;
    rep(N, i) {
        //最大積載量より重い荷物が来ればfalse
        if (v[i] > c) return false;
        if (tmp + v[i] > c) {
            cnt--;
            tmp = v[i];
        }
        else {
            tmp += v[i];
        }
        if (cnt < 0) return false;
    }
    return true;
}

void solve(void){
    cin >> N >> K;
    v.resize(N);
    rep(N, i) {
        cin >> v[i];
    }

    //ok以上はok、ok未満はng
    ll ok = INF, ng = 0LL;
    //差が位置になるまで（okとngの境界がわかるまで）探索
    while(abs(ok-ng)>1) {
        ll mid = (ok + ng) / 2;
        if (check(mid)) ok = mid;
        else ng = mid;
    }

    cout << ok << endl;

}

int main(void){
  solve();
  //cout << "yui(*-v・)yui" << endl;
  return 0;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,a,i;
    long long int s=0;
    cin >>n>>a;
    long long int b[n];
    for (int i=0;i<n;i++){
        cin >> b[i];
    }
    sort(b, b+n, greater<int>()); 
  for(i=a;i<n;i++){
    s=s+b[i];
  }
    cout << s<<"\n";
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(){
	for(;;){
		int H,W,i,l;
		cin >> H >> W;
		if(H==0 && W==0)break;

		for(i=0; i<H; i++){
			for(l=0; l<W; l++){
				if((i%2==1 && l%2==1) || (i%2==0 && l%2==0)){
					cout << "#";
				} else if((i%2==0 && l%2==1) || (i%2==1 && l%2==0)){
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;	
	}
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll dp[3001][3001][4],A[3001][3001];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int R,C,K;
    cin>>R>>C>>K;
    int r,c,v;
    rep(i,K) cin>>r>>c>>v,A[r-1][c-1]=v;
    rep(i,R)rep(j,C)rep(k,4){
        if(k>0) dp[i+1][j+1][k]=dp[i+1][j+1][k-1];
        dp[i+1][j+1][k]=max({dp[i+1][j+1][k],dp[i+1][j][k],dp[i][j+1][3]});
        if(k>0) dp[i+1][j+1][k]=max({dp[i+1][j+1][k],dp[i+1][j][k-1]+A[i][j],dp[i][j+1][3]+A[i][j]});
    }
    cout<<max({dp[R][C][0],dp[R][C][1],dp[R][C][2],dp[R][C][3]});
}

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

int main(){
  int N, M; cin >> N >> M;
  vector<int> num(N + 1);
  for(int i = 0; i < M; i++){
    int a, b; cin >> a >> b;
    num[a]++; num[b]++;
  }
  bool ok = true;
  for(int i = 0; i <= N; i++){
    if(num[i] % 2 == 1) ok = false;
  }
  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 640
import Data.List
import Control.Applicative

listsumcut :: [Int]->[Int]->[Int]
listsumcut [x] accum =accum
listsumcut (x:xs) (a:accum) = listsumcut xs $ (a+2*x):a:accum

solver (x:y:[]) = abs (x-y)
solver (x:xs) = minimum $ map abs $ listsumcut xs [x-(sum xs)]

main :: IO ()
main = do
    -- スペース区切り整数の入力
    getLine
    list <- map read . words <$> getLine
    -- 出力
    putStrLn $ show $ solver list



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

using namespace std;

int main() {
	
	string x;
	cin >> x;

	int i = 0;
	while (i < x.size() - 1) {
		if (x[i] =='S' && x[i + 1] == 'T') {
			x.erase(x.begin() + i+1);
			x.erase(x.begin() + i);
			i--;
			i--;

		}
		i++;
		if (i < 0) { i = 0; }
		if (x=="") { break; }
	}
	cout << x.size() << endl;
	return 0;
}

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

int main() {
	int a,b,c,d,e;
	cin >> a;
	for(int i=0;i<a;i++){
		cin >> b >> c;
		d=b/c;
		e=b-c*d;
		if(b%c==0){
			cout << c << endl;
		}else{
			cout << e << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3076
use std::cmp::min;

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let a: i16 = read(&mut stdin_lock, &mut buf, b'\n');
    let b: i16 = read(&mut stdin_lock, &mut buf, b'\n');
    let c: i16 = read(&mut stdin_lock, &mut buf, b'\n');
    let d: i16 = read(&mut stdin_lock, &mut buf, b'\n');
    let ans = min(a, b) + min(c, d);
    println!("{}", ans);
}


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

int main()
{

    int x;
    cin>>x;
    vector<int> lol;
    int lni = 0, lnj =0;
    for(int i = 1; i <= sqrt(x); i++)
    {
        for(int j = 0; j< x; j++)
        {
           int potencia = pow(i,j);
           if(potencia<=x)
           {
               lnj = potencia;
           }
           if(potencia>=x)
           {
               lol.push_back(lnj);
               //cout<<lnj<<endl;
               //cout<<"I"<<i<<"J "<<j<<endl;
               break;
           }

        }
    }
    int biggest  = 0;
    for(int i = 0; i < lol.size(); i++)
    {
        if(lol[i]> biggest)
        {
            biggest = lol[i];
        }
    }
    cout<<biggest<<endl;


    return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acos(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.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; }

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	ld h, w;
	cin >> h >> w;
	if(h == 1 || w == 1)
	{
		cout << 1 << endl;
		return 0;
	}
	cout << (ll)ceil((h * w) / 2) << endl;
	return 0;
}

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

int main(void){
    ll N; cin>>N;
    string S; cin>>S;
    ll ans=0;
    for(ll i=0;i<N-2;i++){
        if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp

signed main(){
	string s,t;
	cin>>s>>t;
	int n=s.size();
	int m=t.size();
	string ans="~";
	rep(i,0,n-m+1){
		string S2=s;
		bool ok=true;
		rep(j,0,m){
			if(s[i+j]!='?' && s[i+j]!=t[j]){
				ok=false;
			}
			S2[i+j]=t[j];
		}
		if(ok){
			replace(all(S2),'?','a');
			ans=min(ans,S2);
		}
	}
	if(ans=="~") cout<<"UNRESTORABLE";
	else cout<<ans;
		
		
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
//const ull B1 = 100000007;
const ull B = 11451419191;

ull Hash_table[3000010];
ull po[3000010];


int main(){
    
    string s; cin >> s;
    int n = (int)s.size();
    
    Hash_table[0] = 0;
    po[0] = 1;

    for(int i = 1; i <= n; i++){
        po[i] = po[i - 1] * B;
        Hash_table[i] = Hash_table[i - 1] * B + (ull)(s[i - 1] - 'a' + 1);
    }

    
    ull len = B;
    ull len_i, len_j;

    for(ull i = 1; i <= (ull)((n - 2) / 3); i++){
        //cout << i << endl;
        if((n - 3 * i) % 2 == 1) continue;
        ull j = ((n - 3 * i) / 2);
        if(3*i + 2*j != (ull)n) continue;

        //cout << i << " " << j << endl;
        ull H1 = Hash_table[i] - Hash_table[0] * po[i];
        ull H2 = Hash_table[i + j] - Hash_table[i] * po[j];
        ull H3 = Hash_table[2 * i + j] - Hash_table[i + j] * po[i];
        ull H4 = Hash_table[2 * i + 2 * j] - Hash_table[2 * i + j] * po[j];
        ull H5 = Hash_table[n] - Hash_table[2 * i + 2 * j] * po[n - (2 * i + 2 * j)];

        
        if(H1 == H3 && H3 == H5 && H2 == H4){
            //string A = s.substr(0, i);
            //string B = s.substr(i, j);
            //cout << "Love " << A + B << "!" << endl;
            //return 0;
            
            if(len > i + j){
                len_i = i;
                len_j = j;
                len = i + j;
            }
        }
    }

    

    if(len == B) cout << "mitomerarenaiWA" << endl;
    else{
        string A = s.substr(0, (int)len_i);
        string B = s.substr((int)len_i, (int)(len_j));
        //cout << A << " " << B << endl;
        cout << "Love " << A + B << "!" << endl;
    }
    return 0;
}


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

int main(){
  long long n,m; cin>>n;
  m=n;
  int width=0, x=0; bool nine=true;
  while(m!=0){
    x=m%10;
    if(m>=10 && x!=9)nine=false;
    ++width;
    m/=10;
  }

  if(nine)cout<<9*width+x-9<<endl;
  else cout<<9*width+x-10<<endl;
  
  
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;
#define START 0
#define FORWARD 1
#define BACK 2
using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;
bool comp(const pll &a, const pll &b) {
	return a.first < b.first;
}
//*********************************************************
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
ll gcd(ll a, ll b)
{
	ll tmp, r;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
	//// 引数に０がある場合は０を返す
	//if ((0 == m) || (0 == n))
	//	return 0;

	//// ユークリッドの方法
	//while (m != n)
	//{
	//	if (m > n) m = m - n;
	//	else         n = n - m;
	//}
	//return m;
}//gcd

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll x[100004] = {};
	ll y[100004] = {};
	ll z[25000001] = {};
	vector<tuple<ll, ll>> vec;
	string s;
	string t;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	//cout << LLONG_MAX<< endl;

	cin >> a;
	cin >> b;
	for (int i = 0; i < a; i++)
	{
		cin >> c;
		if (d<=b)
		{
			ans++;
		}
		d += c;
	}
	if (d <= b)
	{
		ans++;
	}

	cout << ans << endl;


	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//sort(x, x + a, std::greater<ll>());

//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得
//
//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}
//
//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え


/*vector<pair<ll, ll> > hoges(a);
for (int i = 0; i < a; i++)
{
cin >> x[i];
cin >> y[i];
hoges[i] = make_pair(x[i], y[i]);
}
sort(hoges.begin(),hoges.end(),comp);
for (int i = 0; i < a; i++)
{
if (hoges[i].second>=b)
{
ans += hoges[i].first*b;
break;
}
else
{
ans += hoges[i].first*hoges[i].second;
b -= hoges[i].second;

}
}*/

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
ll MOD  = 1000000007;
int par[100010];
int Rank[100010];

void init(int n){
    for(int i = 0; i < n; i++){
        par[i] = i;
        Rank[i] = 1;
    }
}

int find(int x){ //根を返す関数
    if(par[x] == x) return x;
    else{
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y){
    int rx = find(x), ry = find(y);
    if(Rank[rx] >= Rank[ry]){
        par[ry] = rx;
        if(Rank[rx] == Rank[ry]){
            Rank[rx]++;
        }
    }
    else{
        par[rx] = ry;
    }
    
}

bool same(int x, int y){
    return find(x) == find(y);
}




int main(void){
    int N,M;
    cin >> N >> M;
    vector<int> p(N);
    for(int i = 0; i < N; i++){
        cin >> p.at(i);
        p.at(i)--;
    }
    
    vector<int> x(M), y(M);
    for(int i = 0; i < M; i++){
        cin >> x.at(i) >> y.at(i);
        x.at(i)--;
        y.at(i)--;
    }
    
    init(N);
    for(int i = 0; i < M; i++){
        unite(x.at(i), y.at(i));
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(p.at(i) == i){
            ans++;
        }
        else if( same(p.at(i),  i) ){
            ans++;
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std; int a, b, c, i, n;
int main() {
	while (true) {
		n = 0;
		cin >> a >> b >> c;
		if (!a) {
			break;
		}
		while(n<c){
			if (a < 2) {
				goto E;
			}
			for (i = 2; i <= sqrt(a); i++) {
				if (a%i == 0) {
					goto E;
				}
			}
			n++;
		E:;
			a += b;
		}
		cout << a - b << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;

int main(){
    long long X;
    cin >> X;
    map<long long, long long> dict;
    for (int i = -1000; i <= 1000;i++){
        long long A = pow(i, 5);
        dict[A] = i;
    }
    for (int i = -1000; i <= 1000; i++){
        long long T = X + pow(i, 5);
        if(dict.count(T)){
            cout << dict[T] << " " << i;
            break;
        }
    }
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int count=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            count++;
        }
    }
    if(count>n-count) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define mod 1000000007
#define PI 3.1415926535897932384626433

using namespace std;

int main(){
    fast;
    int n,i;
    cin >> n;
    int a[n],b[n-1];
    for(i=0;i<n-1;i++){
        cin >> b[i];
    }
    a[0] = b[0];
    int answer = a[0];

    for(i=1;i<n-1;i++){
        if(b[i]>b[i-1]){
            a[i] = b[i-1];
        }
        else{
            a[i] = b[i];
        }
        answer += a[i];
    }
    a[n-1] = b[n-2];
    answer += a[n-1];
    cout << answer;

}


Measured memory_bytes: 3540
N,X = map(int,input().split())
L = [int(i) for i in input().split()]
count = 0
sum = 0
for i in range(N):
    sum += L[i]
    if X < sum:
        break
    elif X == sum:
        count += 1
        break
    count += 1
print(count+1)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	int four=0,two=0,odd=0;
	for(int i = 0; i < n; i++){
		if(a[i]%4==0) four++;
		else if(a[i]%2==0) two++;
		else odd++;
	}

	if(two>0){
		if(four>=odd) cout << "Yes" << endl;
		else cout << "No" << endl;
	}else{
		if(four>=odd-1 && n%2!=0) cout << "Yes" << endl;
		else if(four>=odd && n%2==0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 640
function Main(s){
  s = s.split("\n");
  var n = s[0].split(" ").map(a=>+a);
  var m = n[1];
  n = n[0];
  var x;
  var a = Array(4).fill(0).map(a=>Array(n));
  for(var i = 0; i < n; i++){
    x = s[i+1].split(" ").map(a=>+a);
    a[0][i] = x[0] + x[1] + x[2];
    a[1][i] = x[0] + x[1] - x[2];
    a[2][i] = x[0] - x[1] + x[2];
    a[3][i] = -x[0] + x[1] + x[2];
  }
  var ans = 0;
  for(i = 0; i < 4; i++){
    a[i].sort((a,b)=>a-b);
    var t = 0;
    for(var j = 0; j < m; j++){
      t += a[i][j];
    }
    ans = Math.max(ans, Math.abs(t));
    t = 0;
    for(j = n; j > n - m;){
      t += a[i][--j];
    }
    ans = Math.max(ans, Math.abs(t));
  }
  
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 23208
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m, k = map(int, readline().split())
ab = [list(map(int, readline().split())) for _ in range(m)]
cd = [list(map(int, readline().split())) for _ in range(k)]
uf_p = UnionFind(n + 1)
for a, b in ab:
    uf_p.union(a, b)
ans = [uf_p.size(i) - 1 for i in range(1, n + 1)]
for a, b in ab:
    ans[a - 1] -= 1
    ans[b - 1] -= 1
for c, d in cd:
    if uf_p.same(c, d):
        ans[c - 1] -= 1
        ans[d - 1] -= 1
print(*ans)


Measured memory_bytes: 58988
for i in range(10000):
  stra,op,strb=input().split()
  a=int(stra)
  b=int(strb)

  if op=='?':
    break
  elif op=='+':
    print(a+b)
  elif op=='-':
    print(a-b)
  elif op=='*':
    print(a*b)
  elif op=='/':
    print(a//b)


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

ll N, x;
vector<ll> a(101, 0);

int main(void){
	
	scanf("%lld %lld", &N, &x);
	for(int i = 0; i < N; ++i) scanf("%lld", &a[i]);
	sort(a.begin(), a.begin() + N);
	
	ll sum = 0;
	for(int i = 0; i < N; ++i){
	    x -= a[i];
	    if(x >= 0) ++sum;
	}
	
	if(x <= 0) printf("%lld\n", sum);
	else printf("%lld", sum - 1);
	
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<sstream>
#include<cstdio>
#include<ctime>
#include<utility>
#include<cstdlib>
#include<iterator>
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
typedef unsigned int uint;

ullong fact(ullong ngo) {
	return ngo > 1 ? ngo * fact(ngo - 1) : 1;
}

int main() {
	ullong n;
	cin >> n;
	ullong ans = 1;
	for (ullong i = 2; i <= n; ++i) {
		ans = ans * i % 1000000007;
	}
	cout << ans << endl;
}

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

using namespace std;

typedef long long           ll;
typedef vector<int>         vi;
typedef pair<int,int>       ii;

#define endl                '\n'
#define ff                  first
#define pf                  printf
#define ss                  second
#define MX                  109
#define pb                  push_back
#define DB                  pf("Hi\n")
#define pf1(a)              pf("%d\n",a)
#define sc1(a)              scanf("%d",&a)
#define all(c)              (c).begin(),(c).end()
#define mem(a,b)            memset(a, b, sizeof(a))
#define RD                  freopen("0iuput.txt","r",stdin)
#define WR                  freopen("0uput.txt","w",stdout)
#define TC                  int _T;scanf("%d",&_T);while(_T--)
#define rep(i,a,b)          for(int i=int(a)-(a>b);i!=(b)-(a>b);i+=1-2*(a>b))

map<int,int>m;

int main()
{
    int a,b;
    m[2]=1;
    m[4]=2;
    m[6]=2;
    m[9]=2;
    m[11]=2;
    m[1]=  3;
    m[3]=  3 ;
    m[5]=  3  ;
    m[7]=  3  ;
    m[8]= 3   ;
    m[10]=3    ;
    m[12]=3    ;

    sc1(a);
    sc1(b);

    if(m[a]==m[b])
        pf("Yes\n");
    else
        pf("No\n");
}



Measured memory_bytes: 256
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d",&x)
#define rep(i,x) for(int i=0;i<x;i++)
int n,m,ret=0;
int in[100005];
int v[100005]={};
vector<int>val;
priority_queue<P,vector<P>,greater<P> >que;
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int f; scanf("%d",&f);
		val.pb(f);
	}
	for(int i=0;i<n;i++)
	{
		bool x=0,y=0;
		if(!i) x=1;
		else if(val[i]>val[i-1]) x=1;
		
		if(i==n-1) y=1;
		else if(val[i]>val[i+1]) y=1;
		
		v[i]=2-x-y;
		if(x&&y)
		{
			que.push(mp(m-val[i],i));
			in[i]=0;
		}
	}
	while(!que.empty())
	{
	
		P p=que.top();
		que.pop();
		int x=p.first;
		int id=p.second;
		ret=x;
		if(id && val[id]>val[id-1])
		{
			v[id-1]--;
			if(!v[id-1]) que.push(mp(ret+m-val[id-1],id-1));
		}
		if(id!=n-1 && val[id]>val[id+1])
		{
			v[id+1]--;
			if(!v[id+1]) que.push(mp(ret+m-val[id+1],id+1));
		}
	}
	
	printf("%d\n",ret);
}

Measured memory_bytes: 2860
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

struct SegTree {
    int siz;
    vector<int> node;

    SegTree(vector<int> &v) : siz(1) {
        int N = v.size();
        while (siz < N)
            siz *= 2;
        node.resize(2 * siz - 1, INT_MAX);

        for (int i = 0; i < N; ++i)
            node[i + siz - 1] = v[i];
        for (int i = siz - 2; i >= 0; --i)
            node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }

    void update(int k, int x) {
        k += siz - 1;
        node[k] = x;
        while (k > 0) {
            k = (k - 1) / 2;
            node[k] = min(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    int query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0)
            r = siz;

        if (r <= a || b <= l)
            return INT_MAX;
        if (a <= l && r <= b)
            return node[k];
        int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
};

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

    int N, x;
    cin >> N >> x;
    vector<int> a(2 * N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
        a[i + N] = a[i];
    }

    SegTree segtree(a);
    ll ans = LLONG_MAX;
    for (int i = 0; i < N; ++i) {
        ll tmp = (ll)i * x;
        for (int j = N; j < 2 * N; ++j) {
            tmp += segtree.query(j - i, j + 1);
        }
        ans = min(ans, tmp);
    }

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


Measured memory_bytes: 3664
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

std::vector<std::vector<LL>>G;

// ※！注意！※
// 1-indexで扱う
// MAX_Vはギリギリにしない
const LL MAX_V = 112345;
const LL MAX_LOG_V = 50;
class LCA
{
private:
	LL root = 1;						// 根ノードの番号
	std::vector<std::vector<LL>>parent;
	std::vector<LL>depth;

public:
	void dfs(LL v, LL p, LL d)
	{
		parent[0][v] = p;
		depth[v] = d;
		for (auto i : G[v])
		{
			if (i != p) dfs(i, v, d + 1);
		}
	}

	// 初期化
	void init(LL V)
	{
		parent.resize(MAX_LOG_V, std::vector<LL>(V + 1));
		depth.resize(V + 1);
		dfs(root, -1, 0);
		rep(k, MAX_LOG_V - 1)
		{
			for (LL v = 1; v <= V; ++v)
			{
				if (parent[k][v] < 0) parent[k + 1][v] = -1;
				else parent[k + 1][v] = parent[k][parent[k][v]];
			}
		}
	}

	// uとvのLCAを求める
	LL lca(LL u, LL v)
	{
		if (depth[u] > depth[v]) std::swap(u, v);
		rep(k, MAX_LOG_V)
		{
			if ((depth[v] - depth[u]) >> k & 1) v = parent[k][v];
		}
		if (u == v) return u;
		for (LL k = MAX_LOG_V - 1; k >= 0; --k)
		{
			if (parent[k][u] != parent[k][v])
			{
				u = parent[k][u];
				v = parent[k][v];
			}
		}
		return parent[0][u];
	}

	LL dist(LL u, LL v)
	{
		LL t = lca(u, v);
		return depth[u] + depth[v] - 2 * depth[t];
	}
};

int main()
{
	LL N, u, v;
	in >> N >> u >> v;
	std::vector<LL>A(N - 1), B(N - 1);
	rep(i, N - 1) in >> A[i] >> B[i];

	std::vector<LL>leaves;
	G.resize(N + 1);
	rep(i, N - 1)
	{
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
	for (LL i = 1; i <= N; ++i)
	{
		if (G[i].size() == 1) leaves.push_back(i);
	}

	LL ans = 0;
	LCA tree;
	tree.init(N);
	for (LL t : leaves)
	{
		LL dist_u = tree.dist(t, u);
		LL dist_v = tree.dist(t, v);
		if (dist_u >= dist_v)
		{
			LL dist_uv = tree.dist(u, v);
			ans = std::max(ans, dist_uv / 2);
		}
		else
		{
			ans = std::max(ans, dist_v - 1);
		}
	}

	out << ans << std::endl;
}


Measured memory_bytes: 50672
def wa_exit():
    print('WA')
    exit()


s = input()

if s[0] != 'A':
    wa_exit()
if 'C' not in s[2:-1]:
    wa_exit()
for i, c in enumerate(s):
    if i == 0 or i == s.index('C'):
        continue
    if c.isupper():
        wa_exit()

print('AC')

Measured memory_bytes: 3060