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

//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).end()) i=(c).end(); i!=(c).begin(); --i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define FS first
#define SE second

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//Greatest Common Devider
LL gcd(LL a,LL b){
  if(b == 0) return a;
  return gcd(b,a%b);
}
//------------------------------------------
//Least Common Multiple
//Must be used with GCD
LL lcm(LL a,LL b){
  LL g = gcd(a,b);
  return a / g * b;
}
//grobal var
//------------------------------------------


int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  int N;
  cin >> N ;
  LL ans = 0;
  int mcnt = 0;
  VL A;
  REP(i,N){
    LL tmp;
    cin >> tmp;
    if (tmp<=0) mcnt++; 
    A.PB(abs(tmp));
  }
  REP(i,N) ans += A[i];
  if(mcnt%2!=0)  ans -= *min_element(ALL(A))*2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	a = int(input())
	even=a//2
	odd=(a+1)//2

	print(even*odd)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 38256
n = int(input())

arr = []

for i in range(n):
	a,b = map(int,input().split())
	arr.append([b,a])

arr.sort()

now = 0

for a in arr:
	if now + a[1] > a[0]:
		print("No")
		exit()
	now += a[1]

print("Yes")


Measured memory_bytes: 105344
def main():
    n = input()

    c = int(n[-1])
    ans = ''
    if c == 2 or c == 4 or c == 5 or c == 7 or c == 9:
        ans = 'hon'
    elif c == 0 or c == 1 or c == 6 or c == 8 :
        ans = 'pon'
    elif c == 3:
        ans = 'bon'
    
    print(f'{ans}')
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 9196
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	string s;
	cin>>s;
	int count=0;
	int max=0;
	for(int i=0;i<10;i++){
		if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){
			count++;
			max=(max<count)?count:max;
		}else{
			count=0;
		}
	}
	cout<<max<<endl;

	return 0;
}

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

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		long k = Long.parseLong(str[1]);

		int count = 0;
		int value = 1;

		while (value < k) {
			value--;
			value += n;
			count++;
		}

		System.out.println(count);
	}
}

Measured memory_bytes: 32724
// Last Change: 11/14/2019 20:22:34.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

const double EPS = 1e-6;

struct Point {
  double x, y, z;
  Point() : x(0), y(0), z(0) {
  }
  Point(double a, double b, double c) : x(a), y(b), z(c) {
  }

  Point operator+(const Point &o) const {
    return Point(x + o.x, y + o.y, z + o.z);
  }
  Point operator-(const Point &o) const {
    return Point(x - o.x, y - o.y, z - o.z);
  }
  Point operator*(const double &o) const {
    return Point(x * o, y * o, z * o);
  }
};

double dot(const Point &a, const Point &b) {
  return a.x * b.x + a.y * b.y + a.z * b.z;
}

struct Line {
  Point red, blue;
  Line() : red(Point(0, 0, 0)), blue(Point(0, 0, 0)) {
  }
  Line(Point a, Point b) : red(a), blue(b) {
  }
};

Point project(const Line &a, const Point &p) {
  Point base = a.blue - a.red;
  double t = dot(base, p - a.red) / dot(base, base);
  return a.red + base * t;
}

double norm(const Point &a, const Point &b) {
  Point temp = b - a;
  return dot(temp, temp);
}

double abs(const Point &a, const Point &b) {
  return sqrt(norm(a, b));
}

struct Obstacle {
  Point pos;
  ll r, l;
  Obstacle() : pos(Point(0, 0, 0)), r(0), l(0) {
  }

  bool isCross(const Line &a) {
    Point proj = project(a, pos);
    if (norm(a.red, proj) > norm(a.red, a.blue)
        or norm(a.red, a.blue) <= norm(proj, a.blue)) {
      return false;
    }
    double dist = sqrt(norm(pos, proj));
    if (r - dist >= -EPS) {
      return true;
    } else {
      return false;
    }
  }
};

int main() {
  ll N, Q;
  cin >> N >> Q;

  vector<Obstacle> O(N);
  vector<Line> L(Q);
  for (auto &&e : O) {
    cin >> e.pos.x >> e.pos.y >> e.pos.z >> e.r >> e.l;
  }
  for (auto &&e : L) {
    cin >> e.red.x >> e.red.y >> e.red.z >> e.blue.x >> e.blue.y >> e.blue.z;
  }

  for (auto &&e : L) {
    ll res = 0;
    for (auto &&f : O) {
      if (f.isCross(e)) {
        res += f.l;
      }
    }
    cout << res << endl;
  }
}



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

int main()
{
    int n, m; cin>>n>>m;
    string a[n]; for(auto& s: a) cin>>s;
    string b[m]; for(auto& s: b) cin>>s;

    for(int i=0; i+m<=n; ++i)
        for(int j=0; j+m<=n; ++j) {
            for(int k=0; k<m; ++k)
                for(int l=0; l<m; ++l)
                    if (a[i+k][j+l]!=b[k][l]) goto HOGE;
            cout<<"Yes"<<endl;
            return 0;
HOGE:;
        }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s;
  cin>>s;
  ll n=sz(s);
  rep(i,n){
    cout<<'x';
  }
}

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

const int mod = 1e9+7, maxn = 1e4+5;
string K;
int D, dp[maxn][105][2];

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>K>>D;

    dp[0][0][0] = 1;
    for(int i=0;i<K.length();i++){
        int dig = K[i]-'0';
        for(int j=0; j<D; j++){
            for(int a=0; a<=dig;a++){
                if(a == dig) (dp[i+1][(j+a)%D][0] += dp[i][j][0])%=mod;
                else (dp[i+1][(j+a)%D][1] += dp[i][j][0])%=mod;
            }
            for(int a=0; a<=9;a++){
                (dp[i+1][(j+a)%D][1] += dp[i][j][1])%=mod;
            }
        }
    }
    long long  ans = -1LL+dp[K.length()][0][0]+dp[K.length()][0][1];

    cout<<(ans%mod+mod)%mod<<endl;
    return 0;
}



Measured memory_bytes: 8448
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  int a[4][3][10] = {0};
  rep(i, n) {
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    a[b - 1][f - 1][r - 1] += v;
    if (a[b - 1][f - 1][r - 1] < 0)
      a[b - 1][f - 1][r - 1] = 0;
  }
  rep(i, 4) {
    rep(j, 3) {
      rep(k, 10) {
        cout << " " << a[i][j][k];
      }
      cout << endl;
    }
    if (i != 3) {
      rep(k, 20) cout << "#";
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3064
import sys
input=sys.stdin.readline
#####segfunc######                                                              
def segfunc(x,y):
    return x+y

def init(init_val):
    #set_val                                                                    
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built                                                                      
    for i in range(num-2,-1,-1):
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])
    
def update(k,x):
    k+=num-1
    seg[k]=x
    while k+1:
        k=(k-1)//2
        seg[k]=segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p+=num-1
    q+=num-2
    res=ide_ele
    while q-p>1:
        if p&1==0:
            res=segfunc(res,seg[p])
        if q&1==1:
            res=segfunc(res,seg[q])
            q-=1
        p=p//2
        q=(q-1)//2
    if p==q:
        res=segfunc(res,seg[p])
    else:
        res=segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele=0
n,q=map(int,input().split())
num=2**(n-1).bit_length()
seg=[ide_ele]*2*num
c=list(map(int,input().split()))
lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())) + [i])
lr.sort(key=lambda x: x[1])
ans=[0]*q
ll=0
lastc=[-1]*(n+1)
for l,r,ind in lr:
    l-=1
    r-=1
    while ll<=r:
        if lastc[c[ll]]==-1:
            lastc[c[ll]]=ll
            update(ll,1)
        else:
            update(lastc[c[ll]],0)
            lastc[c[ll]]=ll
            update(lastc[c[ll]],1)
        ll+=1
    ans[ind]=query(l,r+1)
for i in ans:
    print(i)


Measured memory_bytes: 239876
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

const int V=100010;

int n,m;
vector<vector<int>> g(V),g2(V);
vector<int> a(V);
vector<bool> used(V);

void dfs(int v,int now){
	if(used[v]) return ;
	used[v]=true;
	g2[now].push_back(a[v]);
	for(auto itr:g[v]){
		dfs(itr,now);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n>>m; 
	rep(i,n) cin>>a[i];
	rep(i,m){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	if(m==n-1){
		cout<<0<<endl;
		return 0;
	}
	if(n<2*(n-m-1)){
		cout<<"Impossible"<<endl;
		return 0;
	}
	int now=0;
	rep(i,n){
		if(used[i]) continue;
		dfs(i,now);
		now++;
	}
	priority_queue<int,vector<int>,greater<int>> que;
	ll ans=0;
	rep(i,n-m){
		sort(begin(g2[i]),end(g2[i]));
		ans+=g2[i][0];
		FOR(j,1,g2[i].size()) que.push(g2[i][j]);
	}
	rep(i,n-m-2){
		ans+=que.top();
		que.pop();
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 9724
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    A,B,C,D = map(int,input().split())
    A += B
    C += D
    if A > C:
        print('Left')
    elif A == C:
        print('Balanced')
    else:
        print('Right')
if __name__ == '__main__':
    main()

Measured memory_bytes: 9184
(def n (read-line))
(def a (map #(Long/parseLong %) (.split (read-line) " ")))
(def b (map #(Long/parseLong %) (.split (read-line) " ")))
(def c (map #(Long/parseLong %) (.split (read-line) " ")))

(def s1 (reduce + b))
(def s2
  (->> (map #(- %1 %2) (rest a) a)
       (map #(if (= %2 1) %1 0) a)
       (filter #(not= % 0))
       (map #(nth c (dec %)))
       (reduce +)))
(println (+ s1 s2))

Measured memory_bytes: 68264
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int t;
  t = 1;
  while (t--) {
    long long n, i, c = 0, x, j, k;
    map<long long, long long>m;
    cin >> n;
    for (i = 1; i <= 1000; i++)
    {
      for (j = 1; j <= 1000; j++)
      {
        for (k = 1; k <= 1000; k++)
        {
          x = i * i + j * j + k * k + (i * j) + (j * k) + (k * i);
          if(x<=10000){
          m[x]++;
        }
        }
      }
    }
    for(i=1;i<=n;i++)
      {
        cout<<m[i]<<endl;
      }
  }

}

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

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

	int A[N];
	double sum;

	for (int i = 0; i < N; i++){
		cin >> A[i];
		sum += pow(A[i], -1);
	}
	cout << 1 / sum;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Test {
	static void Main(string[] args) {
      var inputs = System.Console.ReadLine()
    	.Split(' ')
    	.Select(s => int.Parse(s))
    	.ToArray();
      int N = inputs[0];
      int cntAC = 0;
      int cntWA = 0;
      int cntTLE = 0;
      int cntRE = 0;
      for(int i = 0; i < N; i++){
        string A = System.Console.ReadLine();
        if(A == "AC"){
          cntAC++;
        }else if(A == "WA"){
          cntWA++;
        }else if(A == "TLE"){
          cntTLE++;
        }else if(A == "RE"){
          cntRE++;
        }
      }
      Console.WriteLine("AC x " + cntAC);
      Console.WriteLine("WA x " + cntWA);
      Console.WriteLine("TLE x " + cntTLE);
      Console.WriteLine("RE x " + cntRE);
	}
}

Measured memory_bytes: 22092
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input!(
    n: usize,
    a: usize,
    b: usize,
    );
    let ans = n / (a + b) * a + if n % (a + b) > a {a} else { n % (a + b) };
    println!("{}",ans);

}


Measured memory_bytes: 4352
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    auto ans = min(c, b/a);
    cout << ans;
}

Measured memory_bytes: 256
while True:
  a=int(input()) ;m,t=[],[]
  if a==0: break
  for i in range(a):
    hoge=map(str,raw_input().split());t.append(hoge[0]);m.append(int(hoge[1]))
  b=int(input())
  if b==0:
    hage=raw_input()
    if hage not in t:
      print 0
    else:
      print m[t.index(hage)]
  else:
    for i in range(b):
      hage=map(str,raw_input().split()); k = int(hage[1]) ;qq=0
      for j in range(k):
        if hage[j+2] not in t: pass
        else:
          qq+= m[t.index(hage[j+2])]
      if m[t.index(hage[0])] > qq:
        m[t.index(hage[0])] = qq
    tt = raw_input()
    if tt not in t:
      print 0
    else:
      print m[t.index(tt)]

Measured memory_bytes: 4280
#n = int(input())
n, a, b = [int(x) for x in input().split()]
#n, m = [int(x) for x in input().split()]


if a == 0:
  print(0)
  quit()

ans = (n//(a+b))*a
if n%(a+b) > a:
  ans += a
else:
  ans += n%(a+b)
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	int a,b,x,y;
	double z;
	scanf("%d %d",&a,&b);
	x=a/b;
	y=a%b;
	z=(double)a/b;
	printf("%d %d %lf\n",x,y,z);
	return 0;
}


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

int N; 
const int MAX_A = 1000001;
vector<int> A;
vector<int> A_l;


int main()
{
    for (int i = 0; i < MAX_A; i++)
    {
        A.push_back(0);
    }

    cin >> N;

    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        A[tmp]++;
        A_l.push_back(tmp);
    }

    int count = 0;

    for (int i = 0; i < N; i++)
    {
        
        int sq = sqrt(A_l[i]);
        bool yes = true;

        if (A[A_l[i]] >= 2) 
        {
            yes = false;
            continue;
        }

        for (int j = 1; j <= sq+1; j++)
        {
            if (j == A_l[i]) break;
            if (A_l[i] % j == 0)
            {
                if (j == 1)
                {
                    if (A[j])
                    {
                        yes = false;
                        break;
                    }
                }
                else 
                {
                    if (A[j] || A[A_l[i] / j])
                    {
                        yes = false;
                        break;
                    }
                }
            }
        }

        if (yes) count++;
    }

    cout << count << endl;


}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

using ll = long long;
const ll INF = 1e18;

int N;
struct Edge {
    int to, cost;
    Edge(int to = -1, int cost = 0) : to(to), cost(cost) {}
};
vector<Edge> G[100005];
int Q, K;
int x[100005], y[100005];

ll dp[100005];
void dfs(int v, int u) {
    for (auto e : G[v]) {
        if (e.to == v) continue;
        if (dp[e.to] != INF) continue;
        dp[e.to] = dp[v] + e.cost;
        dfs(e.to, v);
    }
}
int main() {
    cin >> N;
    rep(i, N - 1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a].push_back(Edge(b, c));
        G[b].push_back(Edge(a, c));
    }
    cin >> Q >> K;
    K--;
    rep(i, 100005) dp[i] = INF;
    dp[K] = 0;
    dfs(K, -1);
    rep(i, Q) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        auto ans = dp[x] + dp[y];
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 13440
h, w, k = map(int, input().split())

s = [list(input()) for _ in range(h)]

c = [-1] * h
for i, r in enumerate(s):
    c[i] = r.count('#')
 
ans = [[-1] * w for _ in range(h)]
first_flag = False
z = []
a = 0
for i in range(h):
    if c[i] == 0:
        if first_flag == False:
            z.append(i)
        else:
            ans[i] = ans[i-1]
    else:
        a += 1
        cnt = 0
        for j in range(w):
            if s[i][j] == "#":
                first_flag = True
                if cnt == 0:
                    cnt += 1
                else:
                    cnt += 1
                    a += 1
            ans[i][j] = a

for i in z[::-1]:
    ans[i] = ans[i+1]
        

for i in range(h):
    print(*ans[i])

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

bool isPalindrome(string s)
{
    return s == string(s.rbegin(), s.rend());
}

int main()
{
    string s; cin >> s;
    if(isPalindrome(s) && isPalindrome(s.substr(0,s.length()/2)) && isPalindrome(s.substr(s.length()/2 + 1)))
    {
        cout << "Yes" << "\n";
    }
    else{cout << "No" << "\n";}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cassert>
using namespace std;
const int MAXN=100000;
typedef long long LL;
int l[MAXN+5],r[MAXN+5],n;
priority_queue <LL> pqkiri;
priority_queue <LL,vector<LL>,greater<LL> >pqkanan;
LL ans=0,konstankiri=0,konstankanan=0;
void urusgeser(int idx){
	int geser;
	//geser untuk pq kiri
	konstankiri+=-(r[idx]-l[idx]);			//karena geser ke kiri jadi minus
	
	//geser untuk pq kanan;
	konstankanan+=(r[idx-1]-l[idx-1]);
}
bool ngecek(){
	return (pqkiri.top()+konstankiri<=pqkanan.top()+konstankanan);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&l[i],&r[i]);
		if(i==1)
		{
			pqkiri.push(l[i]);
			pqkanan.push(l[i]);
			continue;
		}
		urusgeser(i);
		
		if((pqkiri.top()+konstankiri)<=l[i]&&l[i]<=(pqkanan.top()+konstankanan))			//muncul di antaranya
		{
			pqkiri.push(l[i]-konstankiri);
			pqkanan.push(l[i]-konstankanan);
		}
		else if(pqkiri.top()+konstankiri>l[i])							//kasus di sebelah kiri
		{
			pqkiri.push(l[i]-konstankiri);
			pqkiri.push(l[i]-konstankiri);
			LL temp=pqkiri.top()+konstankiri;
			ans+=pqkiri.top()-(l[i]-konstankiri);
			pqkiri.pop();
			pqkanan.push(temp-konstankanan);
		}
		else
		{
			pqkanan.push(l[i]-konstankanan);
			pqkanan.push(l[i]-konstankanan);
			LL temp=pqkanan.top()+konstankanan;
			ans+=(l[i]-konstankanan)-pqkanan.top();
			pqkanan.pop();
			pqkiri.push(temp-konstankiri);
		}
		assert(ngecek());
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2796
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    int n,k;
    cin>>n>>k;
    vector<int> h(n,inf);
    for(int i=0;i<n;i++)cin>>h[i];
    vector<int> dp(n,inf);
    dp[0] = 0;
    //dp[1] = abs( h[1]-h[0] );
    for(int i=1;i<n;i++){
	for(int j=0;j<k && i-j-1>=0;j++)dp[i] = min( dp[i-j-1] + abs(h[i]-h[i-j-1]) , dp[i]) ;
    }
    cout<<dp[n-1]<<endl;
    return 0;

}


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

int main() {
  long long A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  long long dist = abs(B - A);
  long long chase = (V - W) * T;
  if (chase >= dist) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main () {

    int N;
    cin >> N;

    long ans = 0;
    for (int i = 1; i <= N; i++) {
        if (!(i % 3 == 0 || i % 5 == 0)) {
            ans += i;
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

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

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string A, B;
    cin >> A >> B;
    if (A.length() > B.length()) cout << "GREATER" << endl;
    else if (A.length() < B.length()) cout << "LESS" << endl;
    else {
        if (A > B) cout << "GREATER" << endl;
        else if (A < B) cout << "LESS" << endl;
        else cout << "EQUAL" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args){
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String s = reader.readLine();
            String date = s.substring(4);
            String year = "2018";
            String ans = year.concat(date);
            System.out.println(ans);
        } catch (IOException e){
            e.printStackTrace();
        }
        
    }
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    atcoder::dsu uf(n);
    for (int i = 0; i < q; ++i) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t) cout << uf.same(u, v) << '\n';
        else uf.merge(u, v);
    }
    return 0;
}


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

#define oo 1e9
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;

int a,b,c,t;

int main(){
    IO;
    cin>>a>>b>>c;
    t=a;
    a=b;
    b=t;
    t=a;
    a=c;
    c=t;
    cout<<a<<' '<<b<<' '<<c;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 3000
#define MOD 1000000007
char S[MN+5];
int s[MN+5],l[MN+5],r[MN+5],f[MN+5][MN+5];
inline void rw(int&a,int b){if((a+=b)>=MOD)a-=MOD;}
int main()
{
	int n,m,i,j,k;
	n=read();m=read();
	scanf("%s",S+1);
	for(i=1;i<=n;++i)s[i]=s[i-1]+(S[i]=='1');
	for(i=1;i<=m;++i)
	{
		l[i]=read();r[i]=read();
		if(l[i]==l[i-1])r[i-1]=max(r[i-1],r[i]);
		if(r[i]<=r[i-1]){--i;--m;continue;}
	}
	l[i]=r[i]=n+2;f[0][0]=1;
	for(i=j=0;i<=n;++i)
	{
		if(i==l[j+1])++j;
		for(k=0;k<=n;++k)if(f[i][k])
		{
			if(i+1<l[j+1])
			{
				if(i>r[j]||k<=r[j]-i)rw(f[i+1][k],f[i][k]);
				if(k)rw(f[i+1][k-1],f[i][k]);
			}
			else
			{
				if(i>r[j])rw(f[i+1][k+s[r[j+1]]-s[i]],f[i][k]);
				else if(k<=r[j]-i)rw(f[i+1][k+s[r[j+1]]-s[r[j]]],f[i][k]);
				if(k)rw(f[i+1][k-1+s[r[j+1]]-s[r[j]]],f[i][k]);
			}
		}
	}
	printf("%d",f[n+1][0]);
}

Measured memory_bytes: 33920
import sys
from collections import deque, defaultdict
N, K = map(int, input().split())
A = [int(i) - 1 for i in input().split()]

s = set()
s.add(0)
cur = 0
num = 0
d = defaultdict(int)
d[0] = 0
ls = [0]
for i in range(K):
    if A[cur] not in s:
        cur = A[cur]
        num += 1
        d[cur] = i+1
        ls.append(cur)
        s.add(cur)
    else:
        cur = A[cur]
        num += 1
        edges_heiro = num - d[cur]
        nokori = K - num
        print(ls[d[cur] + nokori%edges_heiro] + 1)
        sys.exit()
print(cur + 1)

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

public class Main {

	Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		new Main().run();
	}

	void run() {
		int MAX = 123456 * 2;
		boolean isPrime[] = new boolean[MAX + 1];
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for (int i = 2; i * i <= MAX; i++) {
			if (isPrime[i]) {
				for (int j = i + i; j <= MAX; j += i) {
					isPrime[j] = false;
				}
			}
		}
		int sum[] = new int[MAX + 1];
		sum[0] = 0;
		for (int i = 1; i <= MAX; i++) {
			sum[i] = sum[i - 1];
			if (isPrime[i]) {
				sum[i] += 1;
			}
		}
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			System.out.println(sum[2 * n] - sum[n]);
		}
	}
}

Measured memory_bytes: 23576
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const ll INF=2e15;
const double PI=acos(-1);


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

    int n;
    cin >> n;
    rep(i,n-1) {
        repr(j,i+1,n) {
            bitset<10> biti(i),bitj(j);
            rep(l,10) {
                if (biti[l]!=bitj[l]) {
                    cout << l+1 << ' ';
                    break;
                }
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3624
while 1:
  try:
    c = [0]*101
    while 1:
      a, b = map(int, raw_input().split())
      if a==0==b:break
      c[a] += 1
      c[b] += 1
    c = map(lambda x: x%2, c)
    if c[1] and c[2] and sum(c[3:])==0:print"OK"
    else:print"NG"
  except:break

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

int main() {
  string s;
  cin>>s;
  long long k;
  cin>>k;
  set<char> sc(s.begin(), s.end());
  int n = s.length();
  if (sc.size() == 1) {
    cout<<k * n / 2<<endl;
    return 0;
  }
  int len1 = 0, len2 = 0;
  long long ans = 0;
  if (s[0] == s[n-1]) {
    len1 = 1;
    while (len1 < n && s[len1] == s[0]) {
      ++len1;
    }
    len2 = 1;
    while (n-len2-1 >= 0 && s[n-len2-1] == s[0]) {
      ++len2;
    }
    ans = (k - 1) * ((len1 + len2) / 2) + len1 / 2 + len2 / 2;
  }
  int i = len1;
  while (i < n - len2) {
    int cnt = 1;
    while (i + 1 < n - len2 && s[i] == s[i+1]) {
      ++cnt;
      ++i;
    }
    ++i;
    ans += k * (cnt / 2);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
x,k,d = list(map(int, input().split()))

if x < 0:
  q = (x // d) * -1
  if k < q:
    x = x + d * k
  else:
    ak = (k - q) % 2
    x = x + d * q - d * ak
else:
  q = x // d
  if k < q:
    x = x - d * k
  else:
    ak = (k - q) % 2
    x = x - d * q - d * ak
print(abs(x))

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] x = new int[3];
		x[0] = sc.nextInt();
		x[1] = sc.nextInt();
		x[2] = sc.nextInt();
		
		Arrays.sort(x);
		
		int d1 = x[2] - x[0];
		int d2 = x[2] - x[1];
		int min = 10000;
		
		if(d1 % 2 == 0 && d2 % 2 == 0) {
			min = d1 / 2 + d2 / 2;
		} else if(d1 % 2 == 1 && d2 % 2 == 1) {
			min = (d1 - 1) / 2 + (d2 - 1) / 2 + 1;
		} else if(d1 % 2 == 0 && d2 % 2 == 1) {
			min = d1 / 2 + (d2 - 1) / 2 + 2;
		} else {
			min = (d1 - 1) / 2 + d2 / 2 + 2;
		}
		System.out.println(min);
	}
}


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


int main() {

  int a,b,k;
  
  bool flag = false;

  cin >> k >> a >> b;
  
  for(int i = a; i<=b ; i++){
    if(i%k == 0){
      flag = true;
      break;
    }
  }
  
  if(flag)
    cout << "OK";
  else
    cout << "NG";
  

}



Measured memory_bytes: 3604
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
mA, nA, zc = [], [], 0
dd = []
for a in A:
    if a<0:
        mA.append(a)
    elif a>0:
        nA.append(a)
    else:
        zc += 1
    dd.append(a*a)
#rA = A[::-1]
#print(mA, nA)
lnA = len(nA)
lmA = len(mA)

def F(idx):
    j = lnA-1
    r = 0
    for a in nA:
        while j >= 0:
            if nA[j]*a <= idx:
                break
            j -= 1
        r += j+1
    if idx >= 0:
#        print(2*(zc*N) - zc*zc)
        r += 2*(zc*N) - zc*zc
#    print(r, zc)
    j = 0
    for a in mA[::-1]:
        while j < lmA:
            if mA[j]*a <= idx:
                break
            j += 1
        r += lmA-j
    j = 0
    for a in mA:
        while j < lnA:
            if nA[j]*a <= idx:
                break
            j += 1
        r += 2*(lnA-j)

    for a in dd:
        if a <= idx:
            r-=1
    return r//2
#print(F(448283280358331064))

mx, mn = 2*10**18, -2*10**18
idx = (mx + mn)//2
target = K
while mx - mn > 1:
    if F(idx) < target:
        idx, mn = (idx + mx)//2, idx
        continue
    idx, mx = (idx + mn)//2, idx
print(idx+1)


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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define MOD 1000000007

int main(){
    char c[4];
    cin >> c[0] >> c[1] >> c[2] >> c[3];
    sort(c, c + 4);

    if(c[0] == c[1] && c[2] == c[3] && c[1] != c[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(D: int, N: int):
    if N != 100:
        print(str(N)+"00"*D)
    else:
        N = "101"
        print(str(N) + "00"*D)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    D = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(D, N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
M=10**9+7
H=Hash.new{_1[_2]=0,0}
$<.drop(s=o=1).map{a,b=_1.split.map &:to_r
a==0&&b==0?o-=1:(r,f=b==0?[b,1]:a/b<0?[-b/a,1]:[a/b,0]
H[r][f]+=1)}
H.map{|k,v|t=-1
v.map{t+=2.pow _1,M}
s=s*t%M}
p (s-o)%M

Measured memory_bytes: 74864
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 2000001
#define inf 1e17
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a,b,a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,n,m,m1,m2,n1,n2,o,p1,p2,p3,p4,
q1,q2,q3,q4,r,s,t,x,y,z,sum,mn,flg,flg1,flg2,id1,id2,id3,lim,cost;

int main()
{
    scanf("%lld%lld%lld",&a,&b,&n);
    m=min(b-1,n);
    m=((a*m)/b);
    printf("%lld\n", m);
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 3824
import java.util.Scanner;
import java.util.Stack;

public class Main {
	static Scanner sc;
	
	

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

		x = sc.next();
		long n = x.length();
		char[] X = x.toCharArray();

		
		Stack<Character> S = new Stack<>();
		
		for(int i=0; i<n; i++){
			if(X[i]=='S'){
				S.push(X[i]);
			} else if(X[i]=='T' && S.isEmpty()){
				S.push(X[i]);
			} else if (X[i]=='T' && S.peek()=='S'){
				S.pop();
			} else {
				S.push(X[i]);
			}
		}
		
		System.out.println(S.size());

	}

}


Measured memory_bytes: 16748
#include<bits/stdc++.h>
using namespace std;
double eps=1e-10;
double pi=3.1415926535897932;
double add(double a,double b){
  if(abs(a+b)<eps*(abs(a)+abs(b)))return 0;
  return a+b;
}
struct P{
  double x,y;
  P() {}
  P(double x,double y):x(x),y(y){
  }
  P operator + (P p){
    return P(add(x,p.x),add(y,p.y));
  }
  P operator - (P p){
    return P(add(x,-p.x),add(y,-p.y));
  }
  P operator * (double d){
    return P(x*d,y*d);
  }
  double dot(P p){
    return add(x*p.x,y*p.y);
  }
  double det(P p){
    return add(x*p.y,-y*p.x);
  }
};
bool on_seg(P p1,P p2,P q){
  return (p1-q).det(p2-q)==0&&(p1-q).dot(p2-q)<=0;
}
P intersection(P p1,P p2,P q1,P q2){
  return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));
}
bool cmp_x(const pair<P,int>& p,const pair<P,int>& q){
  P pp=p.first,qq=q.first;
  if(pp.x!=qq.x)return pp.x<qq.x;
  return pp.y<qq.y;
}
vector<pair<P,int>> convex_hull(pair<P,int>* ps,int n){
  sort(ps,ps+n,cmp_x);
  int k=0;
  vector<pair<P,int>> qs(n*2);
  for(int i=0;i<n;i++){
    while(k>1&&(qs[k-1].first-qs[k-2].first).det(ps[i].first-qs[k-1].first)<=0)k--;
    qs[k++]=ps[i];
  }
  for(int i=n-2,t=k;i>=0;i--){
    while(k>t&&(qs[k-1].first-qs[k-2].first).det(ps[i].first-qs[k-1].first)<=0)k--;
    qs[k++]=ps[i];
  }
  qs.resize(k-1);
  return qs;
}
double nolum(P p){
  return pow(p.dot(p),0.5);
}
double kaku(P p,P q){
  double k=p.dot(q)/(nolum(p)*nolum(q));
  if(k<-1)k=-1;
  if(k>1)k=1;
  return acos(k);
}
int main(){
  int n;
  double x[100],y[100];
  cin>>n;
  pair<P,int> ps[n];
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
    P o;
    o.x=x[i];
    o.y=y[i];
    ps[i]=make_pair(o,i);   
  }
  double ans[n];fill(ans,ans+n,0.0);
  vector<pair<P,int>> qs=convex_hull(ps,n);
  for(int i=0;i<qs.size();i++){
    int s=(i-1+qs.size())%qs.size(),t=(i+1)%qs.size();
    int num=qs[i].second;
    //cout<<num<<endl;
    //cout<<qs[s].first.x<<" "<<qs[i].first.x<<" "<<qs[t].first.x<<endl;
    //cout<<qs[s].first.y<<" "<<qs[i].first.y<<" "<<qs[t].first.y<<endl;
    double si=kaku(qs[s].first-qs[i].first,qs[t].first-qs[i].first);
    
    ans[num]=0.5-si/(2*pi);
  }
  for(int i=0;i<n;i++){
    cout<<fixed<<setprecision(9)<<ans[i]<<endl;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
unsigned long long ans(0);

int main() {
	std::string S;
	std::getline(std::cin,S);
	unsigned long long offset = 0;
	unsigned long long addnum = 0;
	for (auto itr : S) {
		if(itr == 'W'){
			ans += offset;
			ans += addnum;
			offset += addnum;
			addnum = 0;
		}
		if(itr == 'B'){
			addnum ++;
		}
	}
	std::cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long l = sc.nextLong();
		int n = sc.nextInt();
		long[] dis = new long[n+1];
		long[] sum = new long[n+1];
		for(int i=1; i<=n; i++) {
			dis[i] = sc.nextLong();
			sum[i] = sum[i-1] + dis[i];
		}

		long ans = 0;
		for(int i=1; i<=n; i++) { // i is the pivot
			// hitting pivot from right
			int right = Math.min(i-1, n-i);
			int left = Math.min(i, n-i);
			ans = Math.max(ans, dis[i] + (sum[i-1] - sum[i-1-right])*2 + left *2*l - 2*(sum[left+i] - sum[i]));
			// hitting pivot from left
			right = Math.min(i-1, n-i+1);
			left = Math.min(n-i, i-1);
			ans = Math.max(ans, l-dis[i] + (sum[i-1] - sum[i-1-right])*2 + left *2*l - 2*(sum[left+i] - sum[i]));
//			System.out.println(ans);
		}
		System.out.println(ans);
	}
}

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

int main(){
    int n;
    cin >> n;
    int R[n];
    for ( int i = 0;i < n ;i++)cin >> R[i];
    int min = R[0];
    int a = R[1]-R[0];
    for ( int i = 1;i < n ;i++){
        if(min > R[i]){ min = R[i];
        }else if(min <= R[i] && a <= R[i]-min) a = R[i]-min;
    }
    cout << a <<endl;
    
    return 0;
}

Measured memory_bytes: 1940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] a = s.toCharArray();
		int count = 0;
			for(int i = 0;i < s.length()/2;i++) {
				if(a[i] == a[s.length()-i-1]) {

				}else {
					count++;
				}
			}

			System.out.println(count);
	}

}


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

vector<long long> calc_divisor(long long n) {
  vector<long long> res;
  for (long long i = 1LL; i*i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      long long j = n / i;
      if (j != i) res.push_back(j);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

int main() {
  long long N;
  cin >> N;
  vector<long long> div = calc_divisor(N);
  long long ans = 0;
  for (long long m : div) {
    if (m == 1) continue;
    if (N / (m-1) == N % (m-1)) ans += m-1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int to, cost; };

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

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}

void zeta(const vec<P>& g, vec<P>& f)
{
   copy(g.begin(), g.end(), f.begin());
   int n = f.size();
   for (int i = 0; (1 << i) < n; i++) {
      for (int j = 0; j < n; j++) {
         if ((j >> i) & 1) {
            vec<int> tmp;
            tmp.PB(f[j].first);
            tmp.PB(f[j].second);
            tmp.PB(f[j ^ (1 << i)].first);
            tmp.PB(f[j ^ (1 << i)].second);
            RSORT(tmp);
            f[j].first = tmp[0];
            f[j].second = tmp[1];
         }
      }
   }
}

signed main()
{
   int N; cin >> N;
   vec<int> A(1 << N);
   rep(s, 0, 1 << N) {
      cin >> A[s];
   }


   vec<P> g(1 << N, MP(0,0));
   rep(s, 0, 1 << N) {
      g[s].first = A[s];
   }

   dump(g)

   vec<P> f(1 << N);
   zeta(g, f);

   int MAX = 0;
   rep(s, 1, 1 << N) {
      MAX = max(MAX, f[s].first + f[s].second);
      cout << MAX << endl;
   }

   return 0;
}


Measured memory_bytes: 13440
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cctype>
#include <cstdlib>
#include <bitset>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <ctype.h>
#include <cmath>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <complex>
#include <functional>
#include <climits>
#include <cassert>
#include <iterator>
#include <math.h>
#include <time.h>
#include <string.h>
#include <locale.h>

#define bit(n) (1<<(n))
#define inf 1000000000
#define eps 1e-9
#define PI 3.1415926535897932385
#define pb push_back
#define sz size()
#define mp make_pair
#define cl clear()
#define all(a) a.begin(),a.end()
#define fill(ar,val) memset(ar,val,sizeof(ar))
#define MIN(a,b) if(a>(b)) a=(b)
#define MAX(a,b) if(a<(b)) a=(b)
#define sqr(x) ((x)*(x))
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
//#define MOD 1000000007
#define bsize 1111


using namespace std;
 // ================================================================== //


int main()
{
    // * Faster Input *//
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    // * ========================================================== * //
    
   string st;
   cin >> st;
   int n = st.size();
   int g=0,p=0;
   for(int i=0;i<n;i++)
   {
       if(st[i] == 'g') g++;
       else p++;
   }
    cout << (int)(n/2) - p << endl;
    
    return 0;
}


Measured memory_bytes: 512
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void solve() {
    auto s = readln.split.map!(to!long);
    auto A = s[0];
    auto B = s[1];
    if (A > B) swap(A, B);
    long ans = 2 * (A - 1);

    long hi = B + 1;
    long lo = A;
    while (hi - lo > 1) {
        long mid = (hi + lo) / 2;
        long AB = mid + A;
        bool ok = true;
        foreach (i; -5..5) {
            long a = (A + mid) / 2 + i;
            long b = AB - a;
            if (a <= A || a > mid) continue;
            if (b < A || b >= mid) continue;
            if (a * b >= A * B) ok = false;
        }
        if (ok) lo = mid;
        else hi = mid;
    }

    ans += lo - A;
    ans.writeln;
}

void main() {
    auto T = readln.chomp.to!int;
    while (T--) solve;
}


Measured memory_bytes: 256