akhauriyash/Code-Regression huggingface dataset:
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#define log(args...)
#else
#define log(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); logf(_it, args); }
void logf(istream_iterator<string> it) {
}
template<typename T, typename ... Args>
void logf(istream_iterator<string> it, T a, Args ... args) {
	cout << *it << " = " << a << endl;
	logf(++it, args...);
}
#endif

#define forn(i,k,n) for(ll i=(k); i<(n); i++)

const double PI = acos(-1);
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

void solve() {
	cini(A);
	cini(B);
	cini(M);
	cinai(a, A);
	cinai(b, B);

	ll ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
	for (int i = 0; i < M; i++) {
		cini(x);
		cini(y);
		cini(c);
		x--;
		y--;
		ans = min(ans, 0LL + a[x] + b[y] - c);
		ans = max(ans, 0LL);
	}
	cout << ans << endl;
}

int main() {
	cin.tie(nullptr);
	std::ios::sync_with_stdio(false);
	solve();
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    Graph graph(N);
    rep(i, N - 1) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    if (N == 1) {
        cout << "First" << '\n';
        return;
    }
    queue<P> queue1;
    queue1.push({0, 0});
    vector<bool> visited(N, false);
    vector<ll> dist(N, 0);
    visited[0] = true;
    while (!queue1.empty()) {
        P p = queue1.front();
        queue1.pop();
        dist[p.first] = p.second;
        for (ll v : graph[p.first]) {
            if (!visited[v]) {
                visited[v] = true;
                queue1.push({v, p.second + 1});
            }
        }
    }
    ll max_v = -1;
    ll max_dist = -1;
    rep2(i, 1, N) {
        if (dist[i] > max_dist) {
            max_dist = dist[i];
            max_v = i;
        }
    }
    queue<P> queue2;
    queue2.push({max_v, 0});
    visited.assign(N, false);
    dist.assign(N, 0);
    visited[max_v] = true;
    while (!queue2.empty()) {
        P p = queue2.front();
        queue2.pop();
        dist[p.first] = p.second;
        for (ll v : graph[p.first]) {
            if (!visited[v]) {
                visited[v] = true;
                queue2.push({v, p.second + 1});
            }
        }
    }
    ll max_v2 = -1;
    ll max_dist2 = -1;
    rep(i, N) {
        if (max_v == i) continue;
        if (dist[i] > max_dist2) {
            max_dist2 = dist[i];
            max_v2 = i;
        }
    }
    if (max_dist2 % 3 == 1) {
        cout << "Second" << '\n';
    } else {
        cout << "First" << '\n';
    }
}

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


Measured memory_bytes: 17776
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define SIZE 1000
int stack[SIZE];
int s;

int main()
{
  char s[SIZE];
  scanf("%[^\n]*s",s);
  printf("%d\n",cal(s));
  return 0;
}

int pop()
{
  if(s<=0) return 0;
  return stack[--s];
}

int push(int a)
{
  stack[s++]=a;
}

int judge(char *s){
  if(*s == '+' || *s == '-'){
    s=s+1;
    if(*s >= '0' && *s <= '9'){
      return 1;
    }
    return 0;
  }

  if(*s >= '0' && *s <= '9'){
    return 1;
  }
  return 0;
}

int getnum(char *s){
  int check=0,n=0;

  if(*s == '+'){
    s++;
  }
  else if(*s == '-'){
    check=1;
    s++;
  }

  while(*s >= '0' && *s <= '9'){
    n = n*10+(*s - '0');
    s++;
  }

  if(check == 1) return -n;
  return n;
}

int cal(char *s){
  int a,b,num;

  while(*s!=NULL){
    if(judge(s)==1){
      num = getnum(s);
      push(num);
      while(*s == '+' || *s == '-'){
	s++;
      }
      while(num){
	num=num/10;
	s++;
      }
    }
    else{
      switch(*s){
      case '+':
	a = pop();
	b = pop();
	push(b+a);
	break;
      case'-':
	a = pop();
	b = pop();
	push(b-a);
	break;
      case'*':
	a = pop();
	b = pop();
	push(b*a);
	break;
      }
      s++;
    }
  }
  return pop();
}
	 


  




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

int main(){

    int x,y;
    cin>>x>>y;

    if((x==1||x==3||x==5||x==7||x==8||x==10||x==12)&&(y==1||y==3||y==5||y==7||y==8||y==10||y==12)){
        cout<<"Yes"<<endl;
    }
    else if((x==4||x==6||x==9||x==11)&&(y==4||y==6||y==9||y==11)){
        cout<<"Yes"<<endl;
    }
    else if((x==2)&&(y==2)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}

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

int main()
{
	int a,b,c,d,min,max;
	cin>>a>>b>>c;
	if(b+c <a)
	{
		if(b>c)
			max=c;
		else
			max=b;
		min=0;
	}
	else
	{
		if(b>c)
			max=c;
		else
			max=b;
		min=(b+c)-a;
	}
	cout<<max<<' '<<min<<endl;
	
	return 0;
}
	

Measured memory_bytes: 256
#include<stdio.h>
#define ll long long
int main()
{
    ll a,b;
    char op;
    ll ans;
    scanf("%lld %c %lld",&a,&op,&b);
    if(op=='+')
        ans=a+b;
    else if(op=='-')
        ans=a-b;
    else if(op=='*')
        ans=a*b;
    else if(op=='/')
        ans=a/b;
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

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

  set<string> St;

  for (int i=0; i<N; i++) {
    string s;
    cin >> s;
    St.insert(s);
  }
  
  cout << St.size() << endl;

}


Measured memory_bytes: 19260
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1L<<32;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll a,b,n,ans=0;cin>>a>>b>>n;
  ans=max(ans,((n*a)/b)-(a*(n/b)));
  if(n%b<b-1){
    ll tmp=((n/b))*b-1;
      ans=max(ans,((tmp*a)/b)-(a*(tmp/b)));
    
  }
  
  
  
  cout<<ans<<endl;
}




Measured memory_bytes: 3572
import std.algorithm.iteration;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main()
{
	auto abcd = readln.split.map!( to!int );
	auto ac = ( abcd[ 0 ] - abcd[ 2 ] ).abs;
	auto ab = ( abcd[ 0 ] - abcd[ 1 ] ).abs;
	auto bc = ( abcd[ 1 ] - abcd[ 2 ] ).abs;
	
	if( ac <= abcd[ 3 ] || ( ab <= abcd[ 3 ] && bc <= abcd[ 3 ] ) )
	{
		writeln( "Yes" );
	}
	else
	{
		writeln( "No" );
	}
}


Measured memory_bytes: 256
import math
import itertools
N = int(input())
x = []
for i in range(N):
    x.append(list(map(int,input().split())))
dis = [[0 for i in range(N)] for j in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
            dis[i][j] = math.sqrt((x[i][0] - x[j][0]) ** 2 + (x[i][1] - x[j][1]) ** 2)
            dis[j][i] = dis[i][j]
sumX = [0]*math.factorial(N)
x = []
for i in range(N):
    x.append(int(i))

for i, nowX in enumerate(itertools.permutations(x,N)):
    for j in range(N-1):
        sumX[i] += dis[nowX[j]][nowX[j+1]]

result = sum(sumX)/(math.factorial(N))
print(result)


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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define FORR(i,a,n) for(int i=a; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
void printfv(VI a){ int n = a.size(); FOR(i, n) cout << a[i] << " "; }

int main(void){
	int a,b;
  	cin >> a >> b;	
  
  	if(a == b){
      cout << 2*a;
    } else {
      cout << 2*max(a,b)-1;
    }
  
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc155/tasks/abc155_b

n = int(input())
a = [int(x) for x in input().split() if int(x) % 2 == 0]
for x in a:
    if not (x % 3 == 0 or x % 5 == 0):
        print("DENIED")
        exit()
print("APPROVED")


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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int a[200000];
int main(){
	int m,n;cin>>m>>n;
	if(m==2){
		int c1=0,c2=0;
		rep(i,n){
			scanf("%d",&a[i]);
			if(a[i]-1!=i%2)c1++;
			else c2++;
		}
		cout<<min(c1,c2)<<endl;
		return 0;
	}
	vector<P>v;
	rep(i,n){
		scanf("%d",&a[i]);
		if(v.empty()||v.back().first!=a[i])v.push_back(P(a[i],1));
		else v.back().second++;
	}
	int cnt=0;
	for(auto p:v){
		cnt+=p.second/2;
	}
	cout<<cnt<<endl;
}



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

ll ncr(ll n, ll r){
  if(n == 1) return 0;

  ll a = 1, b = 1;
  for(int i = 0; i < r; i++){
    a *= (n - i);
  }
  for(int i = 0; i < r; i++){
    b *= (i + 1);
  }
  return a/b;
}

int main(){
  int N;
  cin >> N;
  vector<string> s(N);
  for(int i = 0; i < N; i++){
    cin >> s.at(i);
    sort(ALL(s.at(i)));
  }
  sort(ALL(s));

  int left = 0; int right = 0;
  queue<int> num;
  while(left < N){
    while(right < N && s.at(left) == s.at(right)){
      right++;
    }
    num.push(right - left);
    left = right;
  }

  ll result = 0;
  while(!num.empty()){
    result += ncr((ll)num.front(), 2);
    num.pop();
  }
  cout << result << endl;
  
}

Measured memory_bytes: 7680
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    s = list(input())
    a = list('ABC')
    if s == a:
        print('ARC')
        exit()
    else:
      print('ABC')
    

if __name__ == '__main__':
    solve()


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

#define int long long
typedef pair<int, int> P;

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

int N;
int a[110000];
int sa[110000];
int ans[110000];

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sa[i] = a[i];
    }
    vector<int> active;
    int m = 0;
    for (int i = 0; i < N; i++) {
        if (a[i] > m) {
            m = a[i];
            active.push_back(i);
        }
    }
    sort(sa, sa + N);
    int prev = 0;
    int idx = 0;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        if (sa[i] == a[active[idx]]) {
            ans[active[idx]] = sum + (sa[i] - prev) * (N - i);
            sum = 0;
            prev = sa[i];
            idx++;
            if (idx == active.size())
                break;
        } else {
            sum += sa[i] - prev;
        }
    }
    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
int n,x;
int odd,even, four; 
int main(){
	cin>>n;
	while(n--){
		cin>>x;
		if(x%4==0)four++;
		else if(x%2==0)even++;
		else odd++; 
	}
	string ans;
	if(even==0){
		if(odd<=four+1)ans="Yes";
		else ans="No";
	}else{
		if(odd<=four)ans="Yes";
		else ans="No";	
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void push(int);
int pop(void);

int top,Stack[1000];

int main(){

  int x,y;
  char s[100];

  top=0;

  while( scanf("%s", s) !=EOF){
    if( s[0]=='+'){
      x=pop();
      y=pop();
      push(x+y);
    }else if( s[0]=='-'){
      y=pop();
      x=pop();
      push(x-y);
    }else if( s[0]=='*'){
      x=pop();
      y=pop();
      push(x*y);
    }else{
      push(atoi(s));
    }
  }

  printf("%d",pop());
  printf("\n");


  return 0;

}

void push(int a){
  Stack[++top]=a;
}

int pop(){
  top--;
  return Stack[top+1];
}



Measured memory_bytes: 2100
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
int main() {
  long long n,k;
  cin >> n >> k;
  if(n >= k) n = n%k;
  while(n > k-n){
    n = k-n;
  }
  dunk(n);
  return 0;
}

Measured memory_bytes: 256
<?php
$input = explode(' ', trim(fgets(STDIN)));
 
$a = $input[0];
$b = $input[1];
$c = $input[2];
 
if (($a == $b && $a != $c) || ($a == $c && $a != $b)  || ($b == $c && $a != $b)) {
	echo 'Yes';
}else{
	echo 'No';
}

Measured memory_bytes: 4604
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

namespace MyMod {
  typedef long long ll;
  constexpr ll mod = 1e9+7;
  constexpr ll premax = 200020; std::array<ll, premax> f, rf; bool flag = false;

  ll power (ll e, ll x){
    if (x == 0) return 1LL; if (x % 2 != 0) return ((power(e, x-1) * e) % mod);
    ll temp = power(e, x / 2); return (temp * temp) % mod;
  }
  ll add ( ll a, ll b ) { return ((a%mod) + (b%mod))%mod; }
  ll sub ( ll a, ll b ) { return ( a%mod + mod - b%mod)%mod; }
  ll mul ( ll a, ll b ) { return ((a%mod) * (b%mod)) % mod; }
  ll div ( ll a, ll b ) { return ((a%mod) * power(b,mod-2)) % mod; }
  ll nCk (int n, int k) {
    if ( !flag ) {
      f[0] = 1; for(int i=1; i<premax; i++) f[i] = mul(f[i - 1],i);
      rf[premax-1] = power(f[premax-1], mod-2); for(int i=premax-2; i>=0; i--) rf[i] = mul(rf[i + 1], (i + 1));
      flag = true;
    }
    return mul(f[n], mul(rf[n-k], rf[k]));
  }
  ll nPk (int n, int k) {
    if ( !flag ) {
      f[0] = 1; for(int i=1; i<premax; i++) f[i] = mul(f[i - 1],i);
      rf[premax-1] = power(f[premax-1], mod-2); for(int i=premax-2; i>=0; i--) rf[i] = mul(rf[i + 1], (i + 1));
      flag = true;
    }
    return mul(f[n], rf[n-k]);
  }
};


int main (void) {

  int N, K; std::cin >> N >> K;
  std::vector<std::vector<int>> V(N);
  for(int i=0; i<N-1; i++) {
    int a, b; std::cin >> a >> b;
    V[a-1].push_back(b-1);
    V[b-1].push_back(a-1);
  }

  std::queue<int> q;
  std::vector<ll> memo(N);
  memo[0] = 1;
  for(auto& v : V[0]) {
    memo[v] = 1;
    q.push(v);
  }
  if ( K < V[0].size()+1 ) {
    std::cout << 0 << std::endl;
    return 0;
  }
  ll ans = MyMod::nPk(K, V[0].size()+1);
  while(!q.empty()) {
    int cur = q.front(); q.pop();
    int cnt = 0;
    for(auto& v : V[cur]) {
      if ( memo[v] == 0 ) {
        cnt++;
        q.push(v);
        memo[v] = 1;
      }
    }
    if ( K-2 < cnt ) {
      std::cout << 0 << std::endl;
      return 0;
    }
    ans = MyMod::mul(ans, MyMod::nPk(K-2, cnt));
  } 
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 10488
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int idx(int n){
    if(n<0) return 20-n;
    else return n;
}

bool isArive(vector<int>& w, int r, int time){
    for(int i=-r+1; i<r; i++){
        if(sqrt(r*r-i*i)-r+time/1e5 > w[idx(i)]){
            return false;
        }
    }
    return true;
}

int bin_search(vector<int>& w, int r, int imin, int imax){
    if(imax <= imin){
        return imax;
    }else{
        int imid = (imax+imin)/2;
        if(isArive(w, r, imid)){
            return bin_search(w, r, imid+1, imax);
        }else{
            return bin_search(w, r, imin, imid-1);
        }
    }
}


int main(){
    while(1){
        int r,n;
        cin >> r >> n;
        if(r==0) break;

        vector<int> wall(41, 0); //(int coordinates)
        for(int i=0; i<n; i++){
            int xl,xr,h;
            cin >> xl >> xr >> h;
            for(int j=xl; j<xr; j++){
                wall[idx(j)] = max(wall[idx(j)], h);
            }
        }
        for(int i=19; i>=-19; i--){
            wall[idx(i)] = min(wall[idx(i-1)], wall[idx(i)]);
        }

        int dmsec = bin_search(wall, r, 0, 40*1e5);
        cout << fixed;
        cout << setprecision(5);
        cout << dmsec/1e5 << endl;
    }
    return 0;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    string s;
    cin >> s;
    int x = (s[0]-'0')*10 + s[1]-'0';
    int y = (s[2]-'0')*10 + s[3]-'0';
    
    bool m[2];
    m[0] = (1 <= x && x <= 12);
    m[1] = (1 <= y && y <= 12);

    if(m[0]){
        if(m[1]){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }else{
        if(m[1]){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys

n=int(input())
m=list(map(int,input().split()))

ans=1
if 0 in m:
  print(0)
  sys.exit()

for i in range(n):
  ans=ans*m[i]
  if ans>pow(10,18):
    print(-1)
    sys.exit()

if ans<=pow(10,18):
  print(ans)

Measured memory_bytes: 21796
# -*- coding: utf-8 -*-
 
nk = list(map(int,input().split()))
N, K = nk[0], nk[1]

A = list(map(int,input().split()))


if ( N < K ):	# 何周もループする場合
  cur = 1
  count = 0
  A_chk = [0] * len(A)
  
  while ( A_chk[cur-1]==0 ):
    A_chk[cur-1] = 1	# 行ったことのある町をマークする
    cur = A[cur-1]		# 次の町にテレポート
    count += 1			# テレポート回数
    #print(cur)
  #print("count =",count)
  
  loop_s = cur		# ループの起点になる町をマーク
  count_b = count	# ループ終了時のテレポート回数
  
  cur = 1
  count = 0
  while ( cur != loop_s ):
    cur = A[cur-1]
    count += 1
  #print("count =",count)
  
  before_loop_count = count
  loop_count = count_b - count
  #print(before_loop_count,loop_count)
  
  K_re = ( K - before_loop_count ) % loop_count
  #print(K_re)
  
  cur = loop_s
  for i in range(K_re):
    cur = A[cur-1]
  print(cur)
  
else:	# 正攻法
  cur = 1
  for i in range(K):
    cur = A[cur-1]
    #print(cur)
  print(cur)

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

pair<int, vector<long long> > op(vector<long long> V)
{
  bool allneg = true;
  for(auto x: V) if(x > 0) allneg = false;
  if(allneg)
  {
    if(max_element(V.begin(), V.end()) == V.begin())
    {
      V.pop_back();
      return make_pair((int)V.size(), V);
    }
    else
    {
      vector<long long> nv(V.begin()+1, V.end());
      return make_pair(0, nv);
    }
  }
  
  long long oddsum = 0;
  long long evensum = 0;
  for(int i=0; i<(int)V.size(); ++i)
  {
    if(i%2==0) evensum += max(0LL, V[i]);
    else oddsum += max(0LL, V[i]);
  }
  if(oddsum >= evensum || V[0] <= 0)
  {
    vector<long long> nv(V.begin()+1, V.end());
    return make_pair(0, nv);
  }
  if(V.size()%2 == 0 || V.back() <= 0)
  {
    V.pop_back();
    return make_pair((int)V.size(), V);
  }
  
  //V[0] > 0, V.back() > 0, size >= 3
  if(V[2] < 0)
  {
    // 0 1 2 3 4 5
    //     0 p 4 5
    // size >= 5;
    vector<long long> nv(V.begin()+2, V.end());
    nv[0] = V[0]; nv[1] = V[1]+V[3];
    return make_pair(2, nv);
  }
  else 
  {
    // 0 1 2 3 4 5
    //     p 3 4 5 
    vector<long long>nv(V.begin()+2, V.end());
    nv[0] = V[0]+V[2];
    return make_pair(1, nv);
  }
}
int main()
{
  int N; scanf("%d", &N);
  vector<long long> V; for(int i=0; i<N; ++i){ int t; scanf("%d", &t); V.push_back(t); }
  vector<int> ans;
  while(V.size() != 1)
  {
    int x; tie(x, V) = op(V);
    ans.push_back(x);
  }
  printf("%lld\n", V[0]);
  printf("%d\n", (int)ans.size());
  for(auto x: ans) printf("%d\n", x+1);
  return 0;
}

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

int dp[100010];

int main()
{
    dp[0] = 0;
    for (int n = 1; n <= 100000; n++)
    {
        dp[n] = INT_MAX;
        int power = 1;
        while (power <= n)
        {
            dp[n] = min(dp[n], dp[n - power] + 1);
            power *= 6;
        }
        power = 1;
        while (power <= n)
        {
            dp[n] = min(dp[n], dp[n - power] + 1);
            power *= 9;
        }
    }
    int n;
    cin >> n;

    cout << dp[n] << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k];
    }
}; //comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

template<typename T>
struct BIT {
    int n;
    vector<T> d;
    BIT(int n=0):n(n), d(n+1) {}
    void add(int i, T x=1) {
        for (i++; i <= n; i += i&-i) {
            //i&-iで最下位bitを足している
            d[i] += x;
        }
    }
    T sum(int i) {
        T x = 0;
        for (i++; i; i -= i&-i) {
            x += d[i];
        }
        return x;
    }
    T semiopenSum(int l, int r) {
        // [l,r)の半開区間
        return sum(r-1) - sum(l-1);
    }
};  // BIT<int> bit(N);

mint dp[200005];

int main() {
    // dp、Kが小さい、Kからいくつ選ぶか
    // L と　Rに注目
    // BIT
    int N, K;
    cin >> N >> K;
    vector<P> LR(K);
    rep(i, K) cin >> LR[i].first >> LR[i].second;
    BIT<mint> bit(N);
    bit.add(0);
    dp[0] = 1;
    for (int i = 1; i <= N; i++) {
        for (auto p : LR) {
            if (i - p.first < 0) continue;
            int left = i - p.second, right = i - p.first;
            if (left < 0) left = 0;
            dp[i] += bit.semiopenSum(left, right+1);
        }
        bit.add(i, dp[i]);
    }
    cout << dp[N-1] << '\n';
    return 0;
    // ll, 0, -, 1i, for s&g, debug
}

Measured memory_bytes: 6376
//one punch AC
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define reset(x) memset(x, 0,sizeof(x))
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define nmax 100005
#define MOD 1000000007
#define pii pair<int, int>
#define ll long long
#define Task ""

using namespace std;
typedef pair <int, pii> piii;
int n, root[nmax * 4];
piii a[nmax];
vector <piii> edge;

int get_root(int u) {return root[u] >= 0 ? root[u] = get_root(root[u]) : u; }
bool find(int u, int v) {
    return get_root(u) == get_root(v);
}
void Union(int u, int v) {
    if ((u = get_root(u)) == (v = get_root(v))) return;
    if (root[u] > root[v]) swap(u, v);
    root[u] += root[v];
    root[v] = u;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen(Task".inp", "r", stdin);
//    freopen(Task".out", "w", stdout);
    cin >> n;
    memset(root, -1, sizeof root);
    for (int i = 1; i <= n; i++) cin >> a[i].S.F >> a[i].S.S, a[i].F = i;
    sort(a + 1, a + n + 1, [] (piii a, piii b) {return a.S.F < b.S.F || (a.S.F == b.S.F && a.S.S < b.S.S);} );
    for (int i = 1; i < n; i++) {
        int u = a[i].F, v = a[i + 1].F, c = abs(a[i].S.F - a[i + 1].S.F);
        edge.PB({c, {u, v}});
    }
    sort(a + 1, a + n + 1, [] (piii a, piii b) {return a.S.S < b.S.S || (a.S.S == b.S.S && a.S.F < b.S.F);} );
    for (int i = 1; i < n; i++) {
        int u = a[i].F, v = a[i + 1].F, c = abs(a[i].S.S - a[i + 1].S.S);
        edge.PB({c, {u, v}});
    }
    sort(edge.begin(), edge.end());
    int kq = 0;
    for (auto x:edge) {
        int u = x.S.F, v = x.S.S, c = x.F;
        if (!find(u, v)) {
            Union(u, v);
            kq += c;
        }
    }
    cout << kq << ' ';
    return 0;
}


Measured memory_bytes: 7668
import java.util.Scanner;

public class Main {
	public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		int num1 = scan.nextInt();
		int num2 = scan.nextInt();
		scan.close();
		
		int sum = 0;
		
		if((num1 >= 1 && num1 <=9) && (num2 >= 1 && num2 <=9)) {
			sum = num1 * num2;
		} else sum = -1;
		System.out.println(sum);
	
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#define inf 1000000000
using namespace std;
typedef long long ll;
const int MAXN=1e9+10;
const int MAX=1e5+10;
const double eps=1e-6;

ll n;
ll s[MAX];

int main(){
    #ifdef ONLINE_JUDGE
    #else
    //freopen("output.txt","w",stdout);
    #endif

    ll sum=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%lld",&s[i]);
    }
    if(n==2){
        cout<<(abs(s[2]))*2<<" "<<(abs(s[1]))*2<<endl;
        return 0;
    }
    s[0]=0;s[n+1]=0;
    for(int i=1;i<=n+1;i++)
        sum+=abs(s[i]-s[i-1]);
    for(int i=1;i<=n;i++){
        cout<<sum-(abs(s[i]-s[i-1])+abs(s[i+1]-s[i]))+(abs(s[i+1]-s[i-1]))<<endl;
    }


    return 0;
}


Measured memory_bytes: 2048
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e12;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

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

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

const ll mod = 1e9+7;

int main(){
    ll N; cin >> N;
    vl a(N); REP(i, N) cin >> a[i];
    ll r = 0, ans = 0, tmp = 0;
    REP(l, N){
        while(r < N && ((tmp ^ a[r]) == tmp + a[r])){
            tmp += a[r];
            r++;
        }
        ans += r-l;
        if(l==r) r++;
        tmp -= a[l];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__



void solve(void){
  
  int A, B, C;
  cin >> A >> B >> C;
  
  int ans = C-(A-B);
  if(ans<0){ans=0;}
 
  cout << ans << endl;
  
  return;
   
}

#define TESTCASES	1

int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

  	REP(i,TESTCASES){
    	solve();
    } 
  
    return 0;
}



Measured memory_bytes: 256
week = gets.chomp

case week
when "SUN"
    int = 7
when "MON"
    int = 6
when "TUE"
    int = 5
when "WED"
    int = 4
when "THU"
    int = 3
when "FRI"
    int = 2
when "SAT"
    int = 1
end
    
puts int

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#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() {
    string s;
    string t;
    cin >> s;
    cin >> t;
    int ans = 0;
    for (int i=0; i<s.size(); ++i) {
        if (s[i] != t[i]) {
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3900
#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 res = A / gcd(A, B) * B;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
edges = Array.new(n+1).map{Array.new()}
m.times do
	a, b = gets.split.map(&:to_i)
	edges[a].push(b)
	edges[b].push(a)
end

edges.each do |i|
	i.uniq!
end

def dfs(v, edges, visited)
	if visited.length == visited.count{|i| i == true}
		return 1
	end

	ret = 0

	edges[v].each do |i|
		next if visited[i-1] == true
		visited[i-1] = true
		ret += dfs(i, edges, visited)
		visited[i-1] = false
	end

	return ret
end
visited = Array.new(n, false)
visited[0] = true
puts dfs(1, edges, visited)


Measured memory_bytes: 1788
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
for i in range(n):
        x = int(input())
        for j in range(3):
                for k in range(3):
                        if a[j][k]==x: a[j][k] = 0
ans = dcnt1 = dcnt2 = 0
for i in range(3):
        vcnt = hcnt = 0
        for j in range(3):
                if a[i][j]==0: vcnt += 1
                if a[j][i]==0: hcnt += 1

        if a[i][i]==0: dcnt1 += 1
        if a[2-i][i]==0: dcnt2 += 1
        if vcnt==3 or hcnt==3: ans = 1
if dcnt1==3 or dcnt2==3: ans = 1

if ans: print("Yes")
else: print("No")


Measured memory_bytes: 3064
s = input().split()
k=int(s[0])
s = input().split()
a=int(s[0])
b=int(s[1])
flag=0
for i in range(a,b+1):
    if i%k==0:
        flag=1
        break
if flag==0:
    print('NG')
else:
    print('OK')


Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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 n;
    cin >> n;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
    }
    ll ans=0;
    REP(b,61){
        ll mask=1ll<<b;
        ll zero=0;
        ll one=0;
        REP(i,n){
            if(mask&a[i]){
                one++;
            }
            else{
                zero++;
            }
        }
        ll tmp=zero*one;
        REP(i,b){
            tmp*=2;
            tmp%=MOD;
        }
        ans+=tmp;
        ans%=MOD;
    }
    cout << ans << endl;
}

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

struct node{
  int data;
  node* next;
  node* prev;
};


node* make_node(int _data){
  node* n = new node();
  n -> data = _data;
  n -> next = nullptr;
  n -> prev = nullptr;
  return n;
}



class doubly_linked_list{
public:
  node* front;
  node* end;
  int size;

  doubly_linked_list(){
    front = nullptr;
    end = nullptr;
    size = 0;
  }

  ~doubly_linked_list(){
    node* ptr = front;
    while(ptr != nullptr){
      node* n = ptr->next;
      delete ptr;
      ptr = n;
    }


    size = 0;
  }

  void insert(int x){
    if(front == nullptr){
      front = end = make_node(x);
      size++;
      return;
    }

    //which means front is not nullptr;
    node* n = make_node(x);
    n -> next = front;
    front -> prev = n;
    front = n;
    size++;
    return ;
  }


  void remove(int x){
    if(front == nullptr){
      return;
    }

    if(front == end){
      if(front -> data == x){
	front = end = nullptr;
	size --;
	return;
      }else{
	return;
      }
    }

    node* ptr = front;
    while(ptr != nullptr){
      //remove the node pointed to by ptr
      if(ptr->data == x){
	if(ptr == front){
	  front = ptr -> next;
	  front -> prev = nullptr;
	}else if(ptr == end){
	  end = ptr -> prev;
	  end -> next = nullptr;
	}else{
	  ptr->prev->next = ptr->next;
	  ptr->next->prev = ptr->prev;
	}

	size--;
	return;
      }
      

      ptr = ptr->next;
    }

    //otherwise nothing to do
    return;
  }


  void delete_first(){
    if(front == nullptr){
      return;
    }

    if(front == end){
      front = end = nullptr;
      size --;
      return;
    }

    front = front -> next;
    front->prev= nullptr;
    return;
  }


  void delete_last(){
    if(end == nullptr){
      return;
    }

    if(front == end){
      front = end = nullptr;
      size--;
      return;
    }

    end = end -> prev;
    end -> next = nullptr;
    return ;
  }


  void display(){
    node* ptr = front;
    while(ptr != nullptr){
      cout << ptr->data;
      if(ptr->next != nullptr){
	cout << " ";
      }else{
	cout << endl;
      }

      ptr = ptr->next;
    }
  }
};



  






int main(){
  int q_len;
  scanf("%d", &q_len);
  string cmd;
  int val;
  doubly_linked_list* list = new doubly_linked_list();

  while(q_len > 0){
    cin >> cmd;
    if(cmd == "insert"){
      scanf("%d", &val);
      list->insert(val);
    }else if(cmd == "delete"){
      scanf("%d", &val);
      list->remove(val);
    }else if(cmd == "deleteFirst"){
      list->delete_first();
    }else if(cmd == "deleteLast"){
      list->delete_last();
    }
    

    q_len--;
  }


  list->display();

  

}

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

int main(void)
{
    string s; cin >> s;
    int q; cin >> q;
    int inv = 0;
    int t, f;
    string c;
    for (int i = 0; i < q; i++)
    {
        cin >> t;
        if (t == 1) inv = 1 - inv;
        else
        {
            cin >> f >> c;
            if ((f == 1 && inv == 0) || (f == 2 && inv == 1)) 
                s.insert(0, c);
            else
                s.append(c); 
        }
    }
    int l = s.length();
    for (int i = 0; i < l; i++)
    {
        if (inv == 0) 
            cout << s[i];
        else
            cout << s[l - i - 1]; 
    }
    cout << endl;
}

Measured memory_bytes: 3864
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <memory.h>
using namespace std;

typedef pair<int,int> P;

int main() {
  int N,M;
  cin >> N >> M;
  int A[N];
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  map<int, bool> MAP;
  vector<int> v;
  for(int i = N-1; i >= 0; i--) {
    if(M == 0) break;
    if(MAP.find(A[i]) == MAP.end()) {
      M--;
      v.push_back(A[i]);
      MAP[A[i]] = true;
    }
  }
  for(int i = 0; i < v.size(); i++) {
    printf("%d\n",v[i]);
  }


}

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

int main(){
	int h, w;
	
	for (;;){
		cin >> h >> w;
		if ( h == 0 && w == 0 ) break;
		for ( int i = 1; i <= h; i++ ){
			for ( int j = 1; j <= w; j++ ){
				if ( ( i + j ) % 2 == 0 ){
					cout << "#";
				} else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
return 0;
}


Measured memory_bytes: 3088
public class Main {

  private static void solve() {
    int n = ni();
    int k = ni();
    int[] p = na(n);

    double[] e = new double[n];
    for (int i = 0; i < n; i++) {
      e[i] = (double) (1 + p[i]) / 2;
    }

    double[] sum = new double[n + 1];
    for (int i = 0; i < n; i++) {
      sum[i + 1] = sum[i] + e[i];
    }

    double ret = 0;
    for (int i = 0; i + k <= n; i++) {
      ret = Math.max(ret, sum[i + k] - sum[i]);
    }
    System.out.println(ret);

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 43892
import Control.Monad

import Data.Ord
import Data.List
import Data.Function
import Data.Maybe

import qualified Data.ByteString.Char8 as BS

import Debug.Trace

tuplify2 :: [a] -> (a, a)
tuplify2 (x:y:_) = (x, y)
tuplify2 _ = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInt
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents

main = do
  [nSw,nLight] <- getIntList
  ss <- getIntNList nLight
  swAllOn <- getIntList
  let swMatrix = map (indexToVec nSw 1 . sort . drop 1) ss
  print . sum . map (f swAllOn swMatrix) $ allSw nSw

indexToVec :: Int -> Int -> [Int] -> [Int]
indexToVec n i [] = take (n-i+1) [0,0..]
indexToVec n i indices@(x:xs)
  | x == i    = (1 : indexToVec n (i+1) xs)
  | otherwise = (0 : indexToVec n (i+1) indices)

f :: [Int] -> [[Int]] -> [Int] -> Int
f ps swMatrix sw
  | ps' == ps = trace ("1: "++show(ps)++show(swMatrix)++show(sw)) 1
  | otherwise  = trace ("0: "++show(ps)++show(swMatrix)++show(sw)) 0
  where
    ps' = map (flip mod 2 . sum . zipWith (*) sw) swMatrix

allSw :: Int -> [[Int]]
allSw 0 = [[]]
allSw n = [x:y | x <- [0,1], y <- allSw (n-1)]


Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    
    ll n; cin >> n;
    cout << n*(n+1LL)/2LL-n << endl; 


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int ball[15], success, B[15], C[15];

void dfs(int lb, int lc, int qiu) {
	if (success)//找到一种可行方案 就可以了 不必再递归
		return ;
	//如果确定【11】 最多就【10】 说明已经确定了一种方案  现在看可不可行
	if (qiu > 10) {
		int flag = 1;
		for (int i = 0; i < lb - 1; ++i) {
			if (B[i] >= B[i + 1]) {
				flag = 0;
				break;
			}
		}
		for (int i = 0; i < lc - 1; ++i) {
			if (C[i] >= C[i + 1]) {
				flag = 0;
				break;
			}
		}
		if (flag) {
			success = 1;
		}
		return;
	}

	B[lb] = ball[qiu];
	dfs(lb + 1, lc, qiu + 1);
	C[lc] = ball[qiu];
	dfs(lb, lc + 1, qiu + 1);

}

int main() {
	int n;
	scanf("%d", &n);
	while (n--) {
		for (int i = 1; i <= 10; ++i) {
			scanf("%d", &ball[i]);
		}
		success = 0;
		dfs(0, 0, 1);//代表现在B C没球  现在看ball【1】去哪
		if (success)
			puts("YES");
		else
			puts("NO");
	}

	return 0;
}



Measured memory_bytes: 3128
#include <stdio.h>
#include <math.h>

int main(){

int a,b,c;
 double C,s,l,h,rad;

scanf("%d%d%d",&a,&b,&c);

 rad=c*3.14159265359/180;

C=sqrt(a*a+b*b-2*a*b*cos(rad));


l=a+b+C;

s=0.5*a*b*sin(rad);

h=2*s/a;

printf("%lf\n",s);
printf("%lf\n",l);
printf("%lf\n",h);

return 0;
}

Measured memory_bytes: 1064
#include <stdio.h>
#define INF 100000000
int m[100][100];
int p[100], a;

int min(int a, int b) {
  if (a <= b) return a;
  return b;
}

void matrixChainOrder() {
  int n = a, i, j, l, k, q;
  for (i = 1; i <= n; i++) {
    m[i][i] = 0;
  }
  for (l = 2; l <= n; l++) {
    for (i = 1; i <= n-l+1; i++) {
      j = i+l-1;
      m[i][j] = INF;
      for (k = i; k <= j-1; k++) {
        q = m[i][k] + m[k+1][j] + p[i-1] * p [k] * p[j];
        m[i][j] = min(m[i][j], q);
      }
    }
  }
}

int main() {
  int i, j;
  scanf("%d\n", &a);
  for (i = 0; i < a; i++) {
    scanf("%d%d\n", &p[i], &p[i+1]);
  }
  matrixChainOrder();
  printf("%d\n", m[1][a]);

  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n,k,a[110],dp[101][100010];
long long qz[200000];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	dp[0][k]=1;
	for(int i=1;i<=n;i++){
		memset(qz,0,sizeof(qz));
		for(int j=k;j>=0;j--)
		  qz[j]=qz[j+1]+dp[i-1][j];
		for(int j=k;j>=0;j--){
			dp[i][j]=(qz[j]-qz[j+a[i]+1])%(1000000007);
		}
	}
	printf("%d",dp[n][0]);
}

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

int main() {
  long long A;
  std::cin >> A;
  std::string tmp;
  while (true) {
    char c;
    std::cin >> c;
    if (c == '.')
      break;
    tmp += c;
  }
  char c;
  std::cin >> c;
  tmp += c;
  std::cin >> c;
  tmp += c;
  long long B = std::stoll(tmp);
  std::cout << (long long)(A * B / 100) << std::endl;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    int fb = 0, la = 0, ba = 0;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < s.size()-1; ++j) {
            if (s[j] == 'A' && s[j+1] == 'B') ++ans;
        }
        if (s.front() == 'B' && s.back() == 'A') ++ba;
        else if (s.front() == 'B') ++fb;
        else if (s.back() == 'A') ++la;
    }

    if (ba > 0) {
        ans += ba-1;
        if (fb > 0) {
            ++ans;
            --fb;
        }
        if (la > 0) {
            ++ans;
            --la;
        }
    }
    ans += min(la, fb);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256