akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int cou[114514];
bool so[1919];
vector<int> pri;
int main()
{
	memset(so,false,sizeof(so));
	REP(i,2,1910){
		if(so[i]) continue;
		pri.pb(i);
		for(int j=i+i;j<1900;j+=i) so[j]=true;
	}
	memset(cou,0,sizeof(cou));
	int n;cin>>n;
	REP(i,2,n+1){
		int x=i;
		rep(j,pri.size()){
			if(pri[j]>x) continue;
			while(x%pri[j]==0){
				cou[j]++;x/=pri[j];
			}
		}
	}
	lint out=1,mo=1000000007;
	rep(i,pri.size()){
		out*=(cou[i]+1);out%=mo;
	}
	cout<<out<<endl;
}


Measured memory_bytes: 768
//default
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
int ans=0;
#define answer cout << ans << endl;
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; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

map<string,int> mp;

signed main(){
  int N;
  cin >> N;
  rep(i,N){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  for(auto p:mp){
    ans+=p.second*(p.second-1)/2;
  }
  answer
  return 0;
}


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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int const N = 2e5 + 7;

int a[N], b[N];
ii range[N] = {};

int bit[N] = {};
void add(int x, int val)
{
	while (x < N)
		bit[x] += val, x += (x & -x);
}

int get(int x)
{
	int res = 0;
	while (x)
		res += bit[x], x -= (x & -x);
	return res;
}

int main()
{
	fastio;

	int n;
	cin >> n;

	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	for (int i = 1; i <= n; ++i)
		cin >> b[i];

	bool valid = true;
	for (int i = 1; i <= n; ++i)
	{
		if (a[i] == b[i])
			valid = false;
	}

	if (valid)
	{
		cout << "Yes\n";
		cout << b[1];
		for (int i = 2; i <= n; ++i)
			cout << " " << b[i];
		cout << '\n';

		return 0;
	}


	range[a[1]] = {1, 1};
	for (int i = 2; i <= n; ++i)
	{
		if (a[i] == a[i-1]) range[a[i]].s2 = i;
		else range[a[i]] = {i, i};
	}

	//cout << range[1].f1 << " " << range[1].s2 << '\n';
	//cout << range[2].f1 << " " << range[2].s2 << '\n';
	//cout << range[3].f1 << " " << range[3].s2 << '\n';

	for (int i = 1; i <= n; ++i)
	{
		if (range[b[i]].f1 == 0)
		{
			continue;
		}
		else
		{
			int lt = range[b[i]].f1, rt = range[b[i]].s2;
			if (lt <= i && i <= rt)
			{
				add(1, 1);
				add(max(1, rt - i + 1), -1);

				add(max(1, n-i+lt), 1);
			}
			else if (rt <= i)
			{
				add(max(1, n-i+lt), 1);
				add(max(1, n-i+rt+1), -1);
			}
			else
			{
				add(max(1, lt-i), 1);
				add(max(1, rt-i+1), -1);
			}
		}
	}

	int shift = -1;
	for (int i = 1; i < n; ++i)
	{
		if (get(i) == 0)
		{
			shift = i;
			break;
		}
	}

	debug(shift);

	if (shift == -1)
		cout << "No\n";
	else
	{
		cout << "Yes\n";
		for (int i = 1; i <= n; ++i)
		{
			int idx = (i + n - shift) % n;
			if (idx == 0) idx = n;

			if (i > 1) cout << " ";
			cout << b[idx];
		}
		cout << '\n';
	}

	return 0;
}


Measured memory_bytes: 7396
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

ll gcd(ll a, ll b) {
  return b == 0 ? a : gcd(b, a % b);
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  ll A, B;
  while (cin >> A >> B) {
    ll g = gcd(A, B);
    int res = 1;
    for (ll p = 2; p * p <= g; p++) {
      if (g % p == 0) {
        ++res;
        while (g % p == 0) g /= p;
      }
    }
    if (g != 1) ++res;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

def resolve():
    S=input()
    s="AGCT"
    cnt=0
    ans=0
    for i in range(len(S)):
        if S[i] in s:
            cnt+=1
        else:
            ans=max(ans,cnt)
            cnt=0
    ans=max(ans,cnt)
    print(ans)

#%%submit!    
resolve()


Measured memory_bytes: 38256
use v5.26; # strict say state biwise
use warnings;
use List::Util qw(reduce any all none notall first max maxstr min minstr product sum sum0 pairs unpairs pairkeys pairvalues pairfirst pairgrep pairmap shuffle uniq uniqnum uniqstr);

chomp (my $k = <STDIN>);
my $ans = 0;
my @cal;
my $gcd = sub {
  my ($x, $y) = @_;
  return $cal[$x][$y] if $cal[$x][$y]>0;
  my ($v, $u) = ($x, $y);
  while ($y) {
    my $r = $x % $y;
    $r += $y if $r < 0;
    $x = $y;
    $y = $r;
  }
  $cal[$v][$u] = $x;
  return $x;
};
for my $i (1..$k) {
  for my $j (1..$k) {
    my $c = $gcd->($i, $j);
    for my $l (1..$k) {
      $ans += $gcd->($c, $l);
    }
  }
}
say $ans;

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

using namespace std;

using ll = long long int;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanVecInt(V, N);
    sort(V.begin(), V.end(), greater<int>());
    int A = 0;
    int B = 0;
    REP(i, N){
        if (i % 2 == 0){
            A += V[i];
        }else{
            B += V[i];
        }
    }
    cout << (A - B) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    double a[n];

    for(int i=0;i<n;i++)
    {
        cin>>a[i];

    }

    sort(a,a+n);
    for(int i=0;i<n-1;i++)
    {
        a[i+1]=(a[i]+a[i+1])/2;
    }

    cout<<a[n-1];
    exit(0);
}


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

int main() {
    int a, b;
    int sub;

    cin >> a >> b;

    if(a < b){
        cout << "a < b" << endl;
    }
    else if(a == b){
        cout << "a == b" << endl;
    }
    else if(a > b){
        cout << "a > b" << endl;
    }
}

Measured memory_bytes: 3052
#include <iostream>

using namespace std;

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

    int X;
    cin >> X;

    if (X == 7 || X == 5 || X == 3) {
        cout << "YES" << endl;
    }

    else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

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

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
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;}
//自作関数
template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    ll h;
    cin>>h;
    ll height=1;
    while(h>1){
       h/=2;
        height++;
    }
    ll ans=llpow(2LL,height)-1;
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<utility>
#include<cstring>
#define pb(a)             push_back(a)
#define mp(a,b)           make_pair(a,b)
#define pf printf
#define ff first
#define ss second
#define sef second.first
#define ses second.second
#define ms(a,b)            memset(a, b, sizeof(a))
#define loop(i,a)          for(int i=1;i<=a;i++)
#define pii                pair <int,int>
#define sl(a)              scanf("%I64d",&a)
#define sll(a,b)           scanf("%I64d %I64d",&a,&b)
#define si(a)              scanf("%d",&a)
#define sii(a,b)           scanf("%d %d",&a,&b)
using namespace std ;
typedef long long ll ;
const ll mod = 1e9+7;
ll fastpow(ll n,ll k,ll p)//log k
{
    ll ans = 1 ;
    //n = n%p ;
   // if(n==0){return 0 ;}
    while(k>0)
    {
        if(k&1)
        {
            ans = (ans*n)%p;
        }
        k = k >> 1 ;
        n = (n*n)%p;
    }
    return ans ;
}
int main()
{
  //cout << fastpow(5,6,mod) << endl;
  ll n,k;
  cin >> n >> k ;
  ll gcd[k+5],sum=0;
  for(ll i=1;i<=k;i++)
  {
      ll a = k/i ;
      ll p =  fastpow(a,n,mod)%mod;
      gcd[i] = p;
  }
  for(int i=k;i>0;i--)
  {
      for(int j=i+i;j<=k;j+=i)
      {
          gcd[i]-=gcd[j];
      }
  }
  ll ans = 0 ;
  loop(i,k)
  {
      ll x = (gcd[i]*i)%mod;
      ans = (ans+x)%mod;
  }
  cout << ans << endl;
  return 0 ;
}


Measured memory_bytes: 4392
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
bool valid(string S) {
    F0R(i, sz(S)) {
        if (S[i] != S[sz(S) - i - 1]) return false;
    }
    return true;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    string S; cin >> S; int N = sz(S);
    string A; F0R(i, (N-1)/2) A.pb(S[i]);
    string B; FOR(i, (N+1)/2, N) B.pb(S[i]);
    if (valid(S) && valid(A) && valid(B)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
V = list(map(int, sys.stdin.readline().split()))
V.sort()


def mean(a, b):
    return (a + b) / 2


a = reduce(mean, V)
print(a)


Measured memory_bytes: 22888
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int a,b,x;
  cin >> a >> b >> x;
  COUT( x >= a && x <= a+b ? "YES" : "NO");
  return 0;
}


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

int main (void){
  int a,b,c,x,d,ans = 0;
  cin >> a >> b >> c >> x;

  for(int i = 0;i <= a;i++){
    for(int j = 0;j <= b;j++){
      for(int k = 0;k <= c;k++){
        d = 500 * i + 100 * j + 50 * k;
        if(x == d){
          ans++;
        }
      }
    }
  }

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

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <numeric>
#include <iomanip>
using namespace std;
    
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
    
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
    
class fact {
public:
    int fmod = 1e9+7;
    vector<int> fac, inv;
    fact (int n, int Mod = 1e9+7) {
        fmod = Mod;
        fac = vector<int>(n,0);
        inv = vector<int>(n,0);
        fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
        for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
    }
    ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
    ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
    
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}
int poorpow(int b, int a) {
    int tmp = 1;
    REP (i,a) {
        tmp *= b;
    }
    return tmp;
}


bool solve() {
    string s; cin >> s;
    int n = 0;
    REP (i,4) {
        if (s[i] == '+') n++;
        else n--;
    }
    cout << n << endl;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000003;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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(){
    int a,b,n;
    while(cin >> a >> b,a){
        cin >> n;
        vector<int> x(n),y(n);
        rep(i,n) cin >> x[i] >> y[i],--x[i],--y[i];
        vector<vector<ll>> dp(a,vector<ll>(b,0));
        dp[0][0]=1;
        int da[2]={1,0},db[2]={0,1};
        rep(i,a){
            rep(j,b){
                rep(k,2){
                    int na=i+da[k],nb=j+db[k];
                    if (na>=a||nb>=b) continue;
                    bool NG=false;
                    rep(l,n){
                        if (na==x[l]&&nb==y[l]) NG=true;
                    }
                    if (NG) continue;
                    dp[na][nb]+=dp[i][j];
                }
            }
        }
        cout << dp[a-1][b-1] << endl;
    }
}


Measured memory_bytes: 3088
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,n) for (int i = x;i < n;++i)

int x[200001];

int main() {
	int n;
	scanf("%d", &n);
	ll an = 0;
	f(i, 0, n) {
		int t;
		scanf("%d", &t);
		x[t] = i;
	}
	set<int> s;
	s.insert(-1);
	s.insert(n);
	f(i, 1, n + 1) {
		int l, r;
		set<int>::const_iterator it = s.lower_bound(x[i]);
		r = *it;
		l = *(--it);
		an += (ll)(x[i] - l) * (r - x[i]) * i;
		s.insert(x[i]);
	}
	printf("%lld", an);
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define LL long long
#define maxn 200005
using namespace std;

int main()
{
    LL n;
    cin>>n;
    LL a[maxn];
    LL vis[maxn];
    memset(vis,0,sizeof(vis));
    for(LL i=0;i<n;i++)
    {
        cin>>a[i];
        vis[a[i]]++;
    }
    LL ans=0;
    for(LL i=1;i<=n;i++)
    {
        if(vis[i]>=2)
        {
            ans+=(vis[i]*(vis[i]-1)/2);
        }
    }
    LL tmpans=0;
    //cout<<ans<<endl;
    for(LL i=0;i<n;i++)
    {

        tmpans=ans-vis[a[i]]*(vis[a[i]]-1)/2;
        vis[a[i]]--;
        if(vis[a[i]]>=2)
        {
            tmpans=tmpans+(vis[a[i]]*(vis[a[i]]-1)/2);
        }
        cout<<tmpans<<endl;
        vis[a[i]]++;
    }
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <math.h>
int main(void){
    double a,b,c,s,l,h;
    scanf("%lf %lf %lf",&a,&b,&c);
    c=c*3.14159265/180.0;
    s=a*b*sin(c)/2;
    l=a+b+(sqrt(a*a+b*b-2*a*b*cos(c)));
    h=b*sin(c);
    printf("%.8f\n%.8f\n%.8f\n",s,l,h);
    return 0;
}


Measured memory_bytes: 2008
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);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; }

typedef long long ll;

using namespace std;
struct edge{ll from,to,cost;};


int  main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  ll n,m;
  cin>>n>>m;
  vector<edge>edges(m);
  rep(i,m)
  {
    ll a,b,c;
    cin>>a>>b>>c;
    edges[i]={a,b,c};
  }
  bool update=0;
  ll mm=-1e13;
  vector<ll>dist(n+1,mm);
  dist[1]=0;
  rep(i,n)
  {
    update=0;
    rep(j,m)
    {
      if(dist[edges[j].from]==mm)continue;
      bool tmp=chmax(dist[edges[j].to],dist[edges[j].from]+edges[j].cost);
      if(edges[j].to==n)update|=tmp;
    }
  }
  if(update)cout<<"inf"<<endl;
  else cout<<dist[n]<<endl;

  return 0;

}


Measured memory_bytes: 384
N,M = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]

INF = float('inf')
dist = [INF] * N
dist[0] = 0
for i in range(N):
    for a,b,c in ABC:
        a,b,c = a-1,b-1,-c
        if dist[b] > dist[a] + c:
            dist[b] = dist[a] + c
            if i==N-1 and b == N-1:
                print('inf')
                exit()
print(-dist[-1])

Measured memory_bytes: 9276
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  string s;
  cin >> s;
  cout << (s[0] == s[1] && s[1] == s[2] ? "No" : "Yes") << endl;
  return 0;
}

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

#define INF (1LL << 31 - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define fi first
#define se second

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int n, m;
vector<int> d, t;
map<int, int> mp;
bool flag = true;

int main() {
    cin >> n;
    d.resize(n);
    rep(i,n) {
        cin >> d[i];
        mp[d[i]]++;
    }
    cin >> m;
    t.resize(m);
    rep(i,m) {
        cin >> t[i];
        if (mp[t[i]] > 0) {
            mp[t[i]]--;
        }
        else {
            flag = false;
        }
    }

    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

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

int main(){
  vector<int> x(3);
  rep(i,3) cin >>x[i];
  swap(x[0], x[1]);
  swap(x[0], x[2]);
  cout << x[0] << " " << x[1] << " " << x[2] << endl;
  return 0;
}

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

ll N, E[300005], W[300005];
string S;

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

	cin >> N >> S;
	S = "0" + S;
	for (ll i = 1; i <= N; i++) {
		W[i] = W[i-1];
		if (S[i] == 'W') {
			W[i]++;
		}
	}

	for (ll i = N; i >= 1; i--) {
		E[i] = E[i+1];
		if (S[i] == 'E') {
			E[i]++;
		}
	}

	ll ans = 1e9;
	for (ll i = 1; i <= N; i++) {
		ans = min(ans, W[i-1] + E[i+1]);
	}

	cout << ans << "\n";

}

Measured memory_bytes: 5360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)
const char* LF = "\n";
namespace{struct _{_(){
    cin.tie(0);
    ios::sync_with_stdio(false);
}}a;}

vector<ll> li, ri;
vector<ll> C;

signed main() {
    ll N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    li.resize(Q);
    ri.resize(Q);
    REP(i, Q) {
        cin >> li[i] >> ri[i];
    }
    C.resize(N+1, 0);

    ll cnt = 0;
    bool a = false;
    REP(i, S.size()) {
        if (a) {
            if (S[i] == 'C') {
                cnt++;
            }
            a = false;
        }
        if (S[i] == 'A') {
            a = true;
        }
        C[i+1] = cnt;
    }

    REP(i, Q) {
        cout << C[ri[i]] - C[li[i]] << LF;
    }

    return 0;
}


Measured memory_bytes: 3408
#include <stdio.h>
#include <stdlib.h>

int main(){
	int N, L, i;
	scanf("%d%d", &N, &L);
	int *a = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
	}
	int leave = 0;
	for(i = 1; i < N; i++){
		if(a[i - 1] + a[i] >= L){
			leave = i;
		}
	}
	if(leave == 0){
		printf("Impossible\n");
	}
	else{
		printf("Possible\n");
		for(i = 1; i < leave; i++){
			printf("%d\n", i);
		}
		for(i = N - 1; i > leave; i--){
			printf("%d\n", i);
		}
		printf("%d\n", leave);
	}
	return 0;
}

Measured memory_bytes: 1152
/*    特徴    */

/*    教訓    */

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

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x) == 1) return x; }
long long il() { long long x; if (scanf("%lld", &x) == 1) return x; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

#define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

// -------- template end - //


// - library ------------- //

 

// --------- library end - //


// - main() -------------- //

int main(){


  ll sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  ll x = tx-sx;
  ll y = ty-sy;

  rep(i, x) cout << 'R';
  rep(i, y) cout << 'U';
  rep(i, x) cout << 'L';
  rep(i, y) cout << 'D';

  cout << 'D';
  rep(i, x+1) cout << 'R';
  rep(i, y+1) cout << 'U';
  cout << 'L';
  cout << 'U';
  rep(i, x+1) cout << 'L';
  rep(i, y+1) cout << 'D';
  cout << 'R' << endl;

// ---------- main() end - //
}

Measured memory_bytes: 256
#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 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--)
typedef long long ll;
typedef unsigned long long ull;

int bitsOne[60][300000] = { 0 };
ull A[300000];
ull mulp[60][300001];

int main()
{
	int N, shift = 0;
	ull add, ans = 0;

	cin >> N;
	rep(i, N) cin >> A[i];

	repc(j, 0, N) {
		rep(i, 60) {
			if (i == 0) mulp[i][j] = j;
			else mulp[i][j] = (mulp[i - 1][j] * 2) % MOD;
		}
	}
	
	rep(i, 60) {
		rrep(j, N) {
			if (j == N - 1) {
				if (((A[j] >> shift) & 1) == 1) bitsOne[i][j] = 1;
			}
			else {
				if (((A[j] >> shift) & 1) == 1) bitsOne[i][j] = bitsOne[i][j + 1] + 1;
				else bitsOne[i][j] = bitsOne[i][j + 1];
			}
		}

		shift++;
	}

	shift = 0;

	rep(i, 60) {
		rep(j, N - 1) {
			if (((A[j] >> shift) & 1) == 0) add = bitsOne[i][j + 1];
			else add = (ull)N - j - 1 - bitsOne[i][j + 1];
			add = mulp[i][add];
			ans = (ans + add) % MOD;
		}

		shift++;
	}

	cout << ans << endl;

	return 0;
}

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

typedef pair<int, int> P;
const int M = 1000000007;
const int LM = 500000007;

void warshallfloyd(vector<vector<int>>& d)
{
    int n = d.size();
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            for (int k = 0; k < n; ++k)
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}



int main() {
    while (1) {
        int n, m;
        cin >> n >> m;
        if (!n) return 0;

        vector<vector<int>> led(n, vector<int>(n, LM));
        vector<vector<int>> sed(n, vector<int>(n, LM));
        for (int i = 0; i < n; ++i) {
            led[i][i] = 0;
            sed[i][i] = 0;
        }
        for (int i = 0; i < m; ++i) {
            int x, y, t;
            char sl;
            cin >> x >> y >> t >> sl;
            --x;
            --y;
            if (sl == 'L') {
                led[x][y] = min(led[x][y], t);
                led[y][x] = min(led[y][x], t);
            }
            else {
                sed[x][y] = min(sed[x][y], t);
                sed[y][x] = min(sed[y][x], t);
            }
        }
        warshallfloyd(sed);
        warshallfloyd(led);
        int r;
        cin >> r;
        vector<int> dp(n, LM);
        int prev;
        cin >> prev;
        --prev;
        dp[prev] = 0;
        for (int i = 0; i < r - 1; ++i) {
            int z;
            cin >> z;
            --z;
            vector<int> next(n, LM);
            for (int j = 0; j < n; ++j) {
                next[j] = min(next[j], dp[j] + led[prev][z]);
                for (int k = 0; k < n; ++k) {
                    next[j] = min(next[j], dp[k] + led[prev][k] + sed[k][j] + led[j][z]);
                }
            }
            prev = z;
            dp = next;
        }
        int ans = LM;
        for (int i : dp) {
            ans = min(ans, i);
        }
        cout << ans << "\n";
    }
}

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

using namespace std;

#define MAX_N 30
#define MAX_M 20
#define INF (1<<29)

int N,M,mini,ansS;
bool edge[MAX_M][MAX_N];

class Union_Find{
public:
  int par[MAX_M],rank[MAX_M],size[MAX_M];
  Union_Find(int N){
    for(int i = 0 ; i < N ; i++){
      par[i] = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }

  int find(int x){
    if(par[x] == x){
      return x;
    }
    return par[x] = find(par[x]);
  }

  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y){ return; }
    if(rank[x] < rank[y]){
      par[x] = y;
      size[y] += size[x];
    }else{
      par[y] = x;
      size[x] += size[y];
      if(rank[x] == rank[y]){
        rank[x]++;
      }
    }
  }

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

  int getSize(int x){
    return size[find(x)];
  }
};

bool check(int S){
  int idx = 0,arr[MAX_M];
  if(S == 0){ return false; }
  for(int i = 0 ; i < N ; i++){
    if(S >> i & 1){
      arr[idx++] = i;
    }
  }
  Union_Find uf(M);
  for(int i = 0 ; i < M ; i++){
    for(int j = i+1 ; j < M ; j++){
      if(uf.same(i,j)){ continue; }
      for(int k = 0 ; k < idx ; k++){
        if(edge[i][arr[k]] && edge[j][arr[k]]){
          uf.unite(i,j);
        }
      }
    }
  }
  return (uf.getSize(0) == M);
}

void rec(int idx,int S,int num){
  if(num < mini && check(S)){
    mini = num; ansS = S;
    return;
  }
  if(num == 5 || num >= mini){ return; }
  for(int i = idx ; i < N ; i++){
    if(S >> i & 1){ continue; }
    rec(i+1,S|(1<<i),num+1);
  }
}

int main(){
  int K;
  bool blank = false;
  string lang[MAX_N],in;
  while(cin >> N >> M, N){
    map<string,int> mp;
    memset(edge,false,sizeof(edge));
    if(blank){ cout << endl; }
    blank = true;
    for(int i = 0 ; i < N ; i++){
      cin >> lang[i];
      mp[lang[i]] = i;
    }
    for(int i = 0 ; i < M ; i++){
      cin >> K;
      for(int j = 0 ; j < K ; j++){
        cin >> in;
        edge[i][mp[in]] = true;
      }
    }
    mini = INF;
    rec(0,0,0);
    if(mini == INF){
      cout << "Impossible" << endl;
    }else{
      cout << __builtin_popcount(ansS) << endl;
      for(int i = 0 ; i < N ; i++){
        if(ansS >> i & 1){
          cout << lang[i] << endl;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1224
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n;
int a[MAXN];

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&a[i]); sort(a,a+n);
	int mx2a=0,mx2b=0,mx4=0;
	for(int at=0,to=at;at<n;at=to) {
		while(to<n&&a[to]==a[at]) ++to;
		int cnt=to-at,val=a[at];
		if(cnt>=2) { if(val>mx2a) mx2b=mx2a,mx2a=val; else if(val>mx2b) mx2b=val; }
		if(cnt>=4) { if(val>mx4) mx4=val; }
	}
	ll ret=max((ll)mx2a*mx2b,(ll)mx4*mx4);
	printf("%lld\n",ret);
}

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


Measured memory_bytes: 640
N,K=map(int,input().split())
alist=list(map(int,input().split()))

sum_a=sum(alist)
alist.sort()
#print(sum_a,alist)

#M=1の場合にも対応
divisor_set=set()
for i in range(1,int(sum_a**0.5)+1):
  if sum_a%i==0:
    divisor_set.add(i)
    divisor_set.add(sum_a//i)
divisor_list=list(divisor_set)
divisor_list.sort()
#print(divisor_list)

answer=0
for d in divisor_list:
  rlist=[]
  for a in alist:
    rlist.append((a%d,(d-a%d)%d))
  rlist.sort()
  
  r1list,r2list=[],[]
  for r1,r2 in rlist:
    r1list.append(r1)
    r2list.append(r2)  
  #print(d,r1list,r2list)
  
  for i in range(len(rlist)):
    r1sum=sum(r1list[:i])
    r2sum=sum(r2list[i:])
    if r1sum==r2sum and r1sum<=K:
      answer=d
      break
      
print(answer)

Measured memory_bytes: 51804
N, K, C = map(int, input().split())
S = input()

def solve(S):
    A = []
    for i, s in enumerate(S):
        if s == "o" and (not A or A[-1] + C < i):
            A.append(i)
        if len(A) >= K:
            break
    return A

L = solve(S)
R = reversed(solve(reversed(S)))

print("\n".join(str(l + 1) for l, r in zip(L, R) if l == N - r - 1))

Measured memory_bytes: 33248
n = int(input())
A = list(map(int,input().split()))

sum_a = sum(A)
cum_a = [0]*n
cum_a[0] = A[0]

ans = abs(sum_a-2*cum_a[0])

for i in range(1,n-1):
    cum_a[i] = cum_a[i-1]+A[i]
    ans = min(ans,abs(sum_a-2*cum_a[i]))
print(ans)

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

#define gap " "
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ok cout<<"ok"<<endl
#define dbg(x) cout<<(#x)<<" is "<<x<<endl
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}

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

const int N=1000009;
vector<string>vec;
int fx[]={-1,1,0,0};
int fy[]={0,0,-1,1};

int row,col,k;
int level[N],vis[N];
int id(int r,int c)
{
	 return (r*col)+(c+1);
}
int bfs(int x1, int y1,int x2,int y2)
{
   int idx,lv,i,sx,sy,tx,ty,j,lx,ly;
	 queue<pii> final;
   final.push(mp(x1,y1));
   idx=id(x1,y1);
   level[idx]=0;
   vis[idx]=1;
   pii u;
   while(!final.empty())
   {
      u=final.front(); final.pop();
      lx=u.ff; ly=u.ss;
      lv=level[id(lx,ly)]+1;
      
      for(i=0; i<4; i++)
      {
      	 sx=lx; sy=ly;
      	 for(j=1; j<=k; j++)
      	 {
      	 	 tx=sx+fx[i]; ty=sy+fy[i];
      	 	 idx=id(tx,ty);
      	 	 if(tx>=0 && tx<row && ty>=0 && ty<col && vec[tx][ty]=='.' && (level[idx]<1 || level[idx]>=lv))
      	 	 {   
              level[idx]=lv;
              if(vis[idx]==0)  final.push(mp(tx,ty));
              if(tx==x2 && ty==y2) return level[idx];
              sx=tx; sy=ty;
              vis[idx]=1;
      	 	 }
      	 	 else
      	 	 {
      	 	 	 break;
      	 	 }
      	 	 
      	 }
      }
   }

   return -1;
}
void print()
{
	int i,j,idx;
	for(i=0; i<row; i++)
	{
		for(j=0; j<col; j++)
		{
			 if(vec[i][j]=='.')
			 {
         idx=id(i,j);
         cout<<level[idx];
			 }
			 else cout<<vec[i][j];
		}
		cout<<endl;
	}
}
int main()
{
  fastio; 
  string s;
  char ch;
  int i,ans,x1,y1,x2,y2,j;
  // scanf("%d %d %d",&row,&col,&k);//
   cin>>row>>col>>k;
  // scanf("%d %d %d %d",&x1,&y1,&x2,&y2);// 
  cin>>x1>>y1>>x2>>y2;

  x1--; y1--; x2--; y2--; //for 0 based
  for(i=0; i<row; i++)
  {
     cin>>s;	
  	 vec.pb(s);
  }
   ans=bfs(x1,y1,x2,y2);
   // print();
   cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 11420
n = int(input())
INF = float("inf")
edges = [[] for _ in range(n)]
visited = [False]*n
# edges = [[INF for _ in range(n)] for _ in range(n)]
# edges = [[] for _ in range(n) for _ in range(n)]
d = [INF]*n
d[0] = 0

for _ in range(n):
    ls = list(map(int, input().split()))
    u = ls[0]
    degrees = ls[1]
    data = ls[2:]
  
    for i in range(degrees):
        v = data[i*2]
        cost = data[i*2+1]
        edges[u].append((v, cost))
        # edges[u][v] = cost

#通常版
# for _ in range(n):
#     dmin = float("inf")
#     for i in range(n):
#         if not visited[i] and d[i] < dmin:
#             dmin = d[i]
#             u = i
#     visited[u] = True
#     for v, c in edges[u]:
#         d[v] = min(d[v], d[u] + c)

# for i in range(n):
#     print(i, d[i])

# exit()
#heap版
import heapq

heap = [(0, 0)]
d[0] = 0


while heap:
    du, u = heapq.heappop(heap)
    for v, cost in edges[u]:
        if du + cost < d[v]:
            d[v] = du +  cost
            # visited[u] = True
            heapq.heappush(heap, (d[v], v))

for i in range(n):
    print(i, d[i])



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

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
#define db double
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }	
const int maxn=18;
char s[maxn];
int main()
{
	string sb="YAKI";
	while(scanf("%s",s)!=EOF)
	{
		bool flag=true;
		REP(i,4)
			if(s[i]!=sb[i])
				flag=false;
		if(flag)	printf("Yes\n");
		else	printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
len_a = n
sum_list = sum(a)-a[0]
count = 0
for j,i in enumerate(a):
  if j != len_a -1:
    count += i*sum_list
    sum_list -= a[j+1]
    
print(count%1000000007)

Measured memory_bytes: 31740
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
 
    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define int long long
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    string s;
    void solve()
    {
        cin>>s;
        if(s[2]==s[3] && s[4]==s[5])
        {
            cout<<"Yes"<<endl;
        }
        else
            cout<<"No"<<endl;
 
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
    
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<map>
using std::cin;using std::cerr;
using std::max;using std::min;
#define N 200005
#define ll long long
#define db double
#define pb push_back
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
int n,a,b,ecnt,last[N],fa[N],flag;ll Max1,Max2,l,r,mid,Min[N];
struct node{ll x,y;};
std::vector<node>S[N];
struct road{int to,v,nex;}e[N];
void adde(int u,int v,int w) {e[++ecnt]=(road){v,w,last[u]},last[u]=ecnt;}
bool cmp1(node t1,node t2) {return t1.x<t2.x;}
bool cmp2(node t1,node t2) {return t1.y<t2.y;}
void dfs1(int x,ll d=0)
{
	if(d>Max1) Max2=Max1,Max1=d;
	else Max2=max(Max2,d);
	for(int k=last[x];k;k=e[k].nex) dfs1(e[k].to,d+e[k].v);
}
void dfs2(int x)
{
	if(flag) return;
	int to1=0,to2=0;S[x].clear();
	for(int k=last[x];k;k=e[k].nex)
	{
		dfs2(e[k].to),to1?to2=e[k].to:to1=e[k].to;
		for(int i=0,sz=S[e[k].to].size();i<sz;i++)
			S[e[k].to][i].x+=e[k].v,S[e[k].to][i].y+=e[k].v;
	}
	if(!to1) return void(S[x].pb({0,0}));
	if(flag) return;
	int sz1=S[to1].size(),sz2=S[to2].size();
	if(sz1>sz2) std::swap(to1,to2),std::swap(sz1,sz2);
	std::sort(S[to1].begin(),S[to1].end(),cmp1);
	std::sort(S[to2].begin(),S[to2].end(),cmp2);
	Min[0]=S[to2][0].x;
	for(int i=1;i<sz2;i++) Min[i]=min(Min[i-1],S[to2][i].x);
	for(int i=0,j=sz2-1;i<sz1;i++)
	{
		for(;~j&&S[to1][i].x+S[to2][j].y>mid;j--);
		if(~j) S[x].pb((node){Min[j],S[to1][i].y});
	}
	
	std::sort(S[to1].begin(),S[to1].end(),cmp2);
	std::sort(S[to2].begin(),S[to2].end(),cmp1);
	Min[0]=S[to2][0].y;
	for(int i=1;i<sz2;i++) Min[i]=min(Min[i-1],S[to2][i].y);
	for(int i=0,j=sz2-1;i<sz1;i++)
	{
		for(;~j&&S[to1][i].y+S[to2][j].x>mid;j--);
		if(~j) S[x].pb({S[to1][i].x,Min[j]});
	}
	if(S[x].empty()) flag=1;
}
bool Judge() {flag=0,dfs2(1);return !flag;}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++) scanf("%d%d",&a,&b),adde(a,i,b);
	dfs1(1);
	for(l=0,r=Max1+Max2;l<r;) mid=l+r>>1,Judge()?r=mid:l=mid+1;
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 30324
while True:
    n=input()
    if n==0:
        break
    m,goal,d=input(),input(),input()
    step=[""]*d
    for i in xrange(d):
        step[i]="0"+raw_input()+"0"
    raw=range(n+2)
    for i in xrange(d):
        for j in xrange(1,n+1):
            if step[i][j]=="1":
                raw[j],raw[j+1]=raw[j+1],raw[j]
    ans=0
    if not raw[goal]==m:
        e=raw[goal]
        raw=range(n+2)
        for i in xrange(d):
            if not ans==0:
                break
            for j in xrange(1,n+1):
                if (raw[j]==m and raw[j+1]==e) or (raw[j]==e and raw[j+1]==m):
                    if step[i][j-1]=="0" and step[i][j]=="0" and step[i][j+1]=="0":
                        ans=(i+1,j)
                        break
                if step[i][j]=="1":
                    raw[j],raw[j+1]=raw[j+1],raw[j]
        if ans==0:
            ans=1
    if ans==0 or ans==1:print ans
    else:print " ".join(map(str,ans))

Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

ll dfs(string S, ll cnt, char c){
    bool stp = true;
    rep(i,S.size()){
        if(S[i] != c){
            stp = false;
            break;
        }
    }
    if(stp){
        return cnt;
    }
    string T = S;
    rep(i,S.size()-1){
        if(S[i] == c || S[i+1] == c){
            T[i] = c;
        }
    }
    return dfs(T.substr(0,T.size()-1), ++cnt, c);
}

int main(){
    string S;
    cin >> S;
    ll N = S.size();
    map<char,ll> mp;
    rep(i,N){
        mp[S[i]]++;
    }
    ll ans = 1e18;
    for(auto& e:mp){
        cmin(ans, dfs(S, 0, e.first));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,K,x,sum;
	cin>>N>>K;
	for(int i= 0;i<N;i++){
		cin>>x;
		if(x>K-x){
		sum +=(K-x)*2;
		}else{
		sum +=x*2;
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256