akhauriyash/Code-Regression huggingface dataset:
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
    string s,t;cin>>s>>t;
    int i;
    if(sz(t)!=sz(s)+1){cout<<"No\n";return;}
    fo(i,0,sz(s))
    if(s[i]!=t[i]){cout<<"No\n";return;}
    
    cout<<"Yes\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//If wrong on pretest 2 means logically wrong


/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


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

int main() {
  string S;
  cin >> S;
  if(S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3)){
    cout << "Bad" << endl;
  }
  else{
    cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int N = sc.nextInt();
				if(N == 0) break;
				int S = 1;
				
				if(N == 1) {
					System.out.println("deficient number");
					continue;
				}
				
				for(int i=2; i*i<=N; i++) {
					if(N % i == 0) {
						if(i * i == N) S += i;
						else  S +=  i + N / i;
					}
				}
				if(N == S) System.out.println("perfect number");
				else if(N > S) System.out.println("deficient number");
				else System.out.println("abundant number");
			}
		}
	}
}


Measured memory_bytes: 26748
n = int(input())
a = input().split()
odd = 0
count = 0
while odd == 0:
    for k in range(n):
        if int(a[k]) % 2 ==1:
            odd = 1
        else: 
            a[k] = int(a[k]) / 2
    count+=1

count-=1
    
print(count)

Measured memory_bytes: 38768
#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.at(i);
    }

    // 奇数番目、偶数番目に各数字が何回登場したか
    map<int, int> hash_odd, hash_even;
    for (int i = 0; i < n; i++) {
        if (i%2==0) {
            if (hash_odd.find(v.at(i)) != hash_odd.end()) {
            hash_odd.at(v.at(i))++;
            } else {
                hash_odd[v.at(i)] = 1;
            }
        } else {
            if (hash_even.find(v.at(i)) != hash_even.end()) {
            hash_even.at(v.at(i))++;
            } else {
                hash_even[v.at(i)] = 1;
            }
        }
    }

    // それぞれの最頻値をもとめる
    int cnt_odd_first = 0, cnt_even_first = 0;
    int val_odd_first, val_even_first;
    for (const auto& x : hash_odd) {
        if (x.second > cnt_odd_first) {
            val_odd_first = x.first;
            cnt_odd_first = x.second;
        }
    }
    for (const auto& x : hash_even) {
        if (x.second > cnt_even_first) {
            val_even_first = x.first;
            cnt_even_first = x.second;
        }
    }

    // 最頻値が一致しない場合はここで終了
    if (val_odd_first != val_even_first) {
        // 全体から変更しないものを引いた数
        cout << n - cnt_odd_first - cnt_even_first << endl;
        return 0;
    }

    // 2番目に多いものをもとめる
    int cnt_odd_second = 0, cnt_even_second = 0;
    int val_odd_second, val_even_second;
    for (const auto& x : hash_odd) {
        if (x.second > cnt_odd_second && x.first != val_odd_first) {
            val_odd_second = x.first;
            cnt_odd_second = x.second;
        }
    }
    for (const auto& x : hash_even) {
        if (x.second > cnt_even_second && x.first != val_even_first) {
            val_even_second = x.first;
            cnt_even_second = x.second;
        }
    }
    
    // 変更が少ない方を採用する
    if (cnt_odd_second > cnt_even_second) {
        cout << n - cnt_odd_second - cnt_even_first << endl;
    } else {
        cout << n - cnt_odd_first - cnt_even_second << endl;
    }
}

Measured memory_bytes: 5376
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    V = LI()
    C = LI()
    
    ans = sum([V[i] - C[i] for i in range(N) if V[i] - C[i] > 0])
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10104
#include<stdio.h>
#define INFTY 2000000000;
int n,sum=0;
void mergesort(int*,int,int);
void merge(int*,int,int,int);
int main(){
  int i,a[500000],left,right;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  left=0; right=n;
  mergesort(a,left,right);
  for(i=0;i<n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[i]);
  printf("%d\n",sum);
  return 0;
}
void mergesort(int a[],int left, int right){
  int mid;
  if((left+1)<right){
    mid=(left+right)/2;
    mergesort(a,left,mid);
    mergesort(a,mid,right);
    merge(a,left,mid,right);
  }
}
void merge(int a[],int left,int mid,int right){
  int n1,n2,i,j,k;
  n1 = mid-left;
  n2 = right-mid;
  int l[n1+1],r[n2+1];
  for(i=0;i<n2;i++){
    r[i]=a[mid+i];
  }
  for(i=0;i<n1;i++){
    l[i]=a[left+i];
  }
  l[n1]=r[n2]=INFTY;
  i=j=0;
  for(k=left;k<right;k++){
    sum++;
    if(l[i]<=r[j]){
      a[k]=l[i];
      i++;
    }
    else{
      a[k]=r[j];
      j++;
    }
  }
}



Measured memory_bytes: 5636
// 6/18 振り返り
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using ll = long long;
const int mod = 1000000007;
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, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

    vector<mint> res(K + 1);

    for (int x = K; x >= 1; x--) {
        // cout << "here?" << endl;
        mint count = mint(K / x).pow(N);

        for (int y = x + x; y <= K; y += x) {
            // cout << x << endl;
            count -= res[y];
        }

        res[x] = count;
    }

    mint ans = 0;
    for (int x = 1; x <= K; x++) {
        // printf("x, res[x] = %d, %d\n", x, res[x].x);
        ans += res[x] * x;
    }

    cout << ans.x << endl;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
  int n; cin >> n;
  cout << n / 3 << endl;  
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v, int num=0){
  if(num == 0) num = (int)v.size();
	for(int i=0; i<num; i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

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)){
      d[i] += x;
    }
  }
  
  T sum(int i){
    T x = 0;
    for(i++; i; i-=i&(-i)){
      x += d[i];
    } 
    return x;
  }
};

int main(){

  int INF = 100000;
  vector<int> num_divisor(INF+1, 0);
  for(int i=2; i<=INF; i++){
    for(int j=i; j<=INF; j+=i){
      num_divisor[j]++;
    }
  }

  //BITでも累積和でも解ける てか累積和のほうが知識レベル的に簡単だね
  BIT<int> bi(INF+1);
  // vector<int> wa(INF+1, 0);//累積和
  for(int i=2; i<=INF; i++){
    if(num_divisor[i] == 1){
      if(num_divisor[(i+1)/2] == 1) bi.add(i);
    }
    // bool like_2017 = false;
    // if(num_divisor[i] == 1){
    //   if(num_divisor[(i+1)/2] == 1) like_2017 = true;
    // }
    // wa[i] = wa[i-1] + like_2017;
  }
  int Q;
  cin >> Q;
  for(int i=0; i<Q; i++){
    int l, r;
    cin >> l >> r;
    cout << bi.sum(r) - bi.sum(l-1) << endl;
    // cout << wa[r] - wa[l-1] << endl;
  }

	return 0;
}



Measured memory_bytes: 3868
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
#define M 1046527
using namespace std;
typedef long long ll;

int s[100001],n;
char dic[M][12];
ll getchar(char s)
{
	if(s=='A') return 1;
	else if(s=='C') return 2;
	else if(s=='G') return 3;
	else if(s=='T')	return 4;
	else return 0;
}
ll getkey(char str[])
{
	ll i,sum=0,p=1;
	for(i=0;i<strlen(str);i++)
	{
		sum+=p*getchar(str[i]);
		p*=5;
	}
	return sum;
}
ll h1(ll key){
	return key%M;
}
ll h2(ll key){
	return 1+(key%(M-1));
}
bool find(char str[])
{
	ll key,i=0,hash;
	key=getkey(str);
	while(i++>=0){
		hash=(h1(key)+i*h2(key))%M;
		if(strcmp(dic[hash],str)==0) return true;//找到 
		else if(strlen(dic[hash])==0) {
			return false;//来到了空地址 ，查询失败
		} 
		//地址冲突，继续循环 
	} 
} 
void insert(char str[])
{
	ll key,i,hash;
	key=getkey(str);
	i=0;
	while(i++>=0){
		hash=(h1(key)+i*h2(key))%M;
		if(strcmp(dic[hash],str)==0) return;//已经插入 
		else if(strlen(dic[hash])==0){//来到空地址，插入 
			strcpy(dic[hash],str);
			return;
		}
		//地址冲突，继续循环 
	}
}
int main(int argc, char *argv[]) {
	char com[14],str[12];
	int n;
	scanf("%d",&n);
	for(ll i=0;i<M;i++)
	{
		dic[i][0]='\0';
	}
	for(ll i=0;i<n;i++)
	{
		scanf("%s %s",com,str);
		if(com[0]=='i'){
			insert(str);
		}else if(com[0]=='f'){
			if(find(str))
				printf("yes\n");
			else
				printf("no\n");
		}
	}
	return 0;
}


Measured memory_bytes: 15424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg((ll)1e12)+3;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll n,k;
ll d[MAXn];
int main(){
  IOS();
  cin >> n >> k;
  REP (i,n) cin >> d[i];

  ll bst = 0;
  for (ll i=MAXlg-1;i>=0;i--) {
    ll cnt = 0;
    REP (j,n) if ((d[j]>>i)&1) cnt++;
    if (cnt <= n/2 && bst + (1LL<<i) <= k) bst += (1LL<<i);
  }
  debug(bst);
  ll tt = 0;
  REP (i,n) tt += (bst^d[i]);
  cout << tt << endl;
}


Measured memory_bytes: 1024
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


class Solver:

    def __init__(self, n, k, a):
        self.n = n
        self.k = k
        self.a = a
        self.pos = 0 # city id starts from 0 in this code
        self.ticket = k
        self.diary = [False] * n
        self.nostalgia = False
        self.hometown = -1
        self.cycle_size = 0

    def run(self):
        #print('hoge') # debug
        self.pos = 0
        self.diary[0] = True
        while not self.nostalgia:
            #print('self.ticket') # debug
            #print(self.ticket) # debug
            if self.ticket == 0:
                return self.answer()
            self.jump()
        self.count_cycle_size()
        self.ticket = self.ticket % self.cycle_size
        while not self.ticket == 0:
            self.pos = self.a[self.pos]
            self.ticket -= 1
        return self.answer()

    def count_cycle_size(self):
        self.cycle_size = 1
        self.pos = self.a[self.pos]
        while not (self.pos == self.hometown):
            self.pos = self.a[self.pos]
            self.cycle_size += 1

    def jump(self):
        self.ticket -= 1
        self.pos = self.a[self.pos]
        if self.diary[self.pos]:
            self.nostalgia = True
            self.hometown = self.pos
        self.diary[self.pos] = True

    def answer(self):
        # rearrange city id to starts from 1
        return self.pos + 1


def make_to_city_id_starts_from_0(a):
    for i, v in enumerate(a):
        a[i] = v - 1

if __name__ == '__main__':
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    make_to_city_id_starts_from_0(a)

    #print('fuga') # debug
    ans = Solver(n, k, a).run()
    #print('ans') # debug
    print(ans)

    #print('\33[32m' + 'end' + '\033[0m') # debug


Measured memory_bytes: 93288
N = int(input())
s = [0]* N
Middle = 0
Bcount = 0
Acount = 0
ABcount = 0
ans = 0
for i in range(N):
    s[i] = input()
    if s[i][0] == "B" and s[i][-1] == "A":
        ABcount += 1
    elif s[i][0] == "B":
        Bcount += 1
    elif s[i][-1] == "A":
        Acount += 1
    for j in range(len(s[i])-1):
        if s[i][j] == "A" and s[i][j+1] == "B":
            Middle += 1
if ABcount==0 and Acount==0 and Bcount==0:
    ans = Middle
elif Acount == 0 and Bcount==0:
    ans = Middle + ABcount - 1
elif Acount == 0:
    ans = Middle + ABcount
elif Bcount == 0:
    ans = Middle + ABcount
else:
    ans = Middle + ABcount +1 + min(Acount-1,Bcount-1)
print(ans)



    

Measured memory_bytes: 46680
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
    		int N = sc.nextInt();
		if(N == 1) {
			System.out.println("Hello World");
		}
		else {
			int A = sc.nextInt(), B = sc.nextInt();
			System.out.println(A + B);
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
const int MAX = (2e5)+1, INF = 1e9;

int n, m, d[MAX];
vector<int> g[MAX];
queue<int> q;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	fill(d+1, d+n, INF);
	for(int i = 0, u, v; i < m; i++) {
		cin >> u >> v;
		g[u-1].push_back(v-1);
		g[v-1].push_back(u-1);
	}
	q.push(0);
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(int v: g[u]) if(d[v] == INF) {
			q.push(v);
			d[v] = d[u] + 1;
		}
	}
	if(d[n-1] == 2) cout << "POSSIBLE";
	else cout << "IMPOSSIBLE";
}


Measured memory_bytes: 13168
s=input()
l=len(s)

for i in range(1, l+1):
    if i%2==1:
        if s[i-1]=="R" or s[i-1]=="U" or s[i-1]=="D":
            pass
        else:
            print("No")
            exit()
    else:
        if s[i-1]=="L" or s[i-1]=="U" or s[i-1]=="D":
            pass
        else:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3064
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();
    let p: Vec<usize> = (0..n).map(|_| {
        let pi: usize = iterator.next().unwrap().parse().unwrap();
        pi - 1
    }).collect();
    let c: Vec<isize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    let mut ans: isize = std::isize::MIN;
    for start in 0..n {
        let mut visited: Vec<bool> = vec![false; n];
        let mut current = start;
        let mut count = 0;
        let mut score_all = 0;
        let mut score_max = std::isize::MIN;
        while count < k && !visited[p[current]] {
            current = p[current];
            visited[current] = true;
            score_all += c[current];
            score_max = max(score_max, score_all);
            count += 1;
        }

        // ループした場合
        if visited[p[current]] {
            // 1ループのスコアが正の場合
            if score_all > 0 {
                let mut score = score_all * (k / count - 1) as isize;
                let r = k % count + count;

                let mut current = start;
                let mut score_all = 0;
                let mut score_max = std::isize::MIN;
                let mut count = 0;
                while count < r {
                    current = p[current];
                    score_all += c[current];
                    score_max = max(score_max, score_all);
                    count += 1;
                }
                if score_max > 0 {
                    score += score_max;
                }
                ans = max(ans, score);
            } else {
                ans = max(ans, score_max);
            }
        } else {
            ans = max(ans, score_max);
        }
    }
    ans.to_string()
}


Measured memory_bytes: 2320
#include <iostream>
#include <vector>
#define pb push_back
#define mp make_pair
using namespace std;

long long MOD;

vector<int> g[100010];
vector<long long> pref[100010];
vector<long long> suf[100010];
long long dp[100010];
long long ans[100010];

void dfs(int v, int p) {
	int n = int(g[v].size());
	for (int i = 0; i < n; i++) {
		int to = g[v][i];
		if (to == p) continue;
		dfs(to, v);
		dp[v] = dp[v] * (dp[to] + 1) % MOD;
	}
}

void calc(int v, int p) {
	ans[v] = dp[v];
	int n = int(g[v].size());
	pref[v].resize(n + 5, 1ll);
	suf[v].resize(n + 5, 1ll);
	for (int i = 0; i < n; i++) {
		int to = g[v][i];
		pref[v][i + 1] = pref[v][i] * (dp[to] + 1) % MOD;
	}
	for (int i = n - 1; i >= 0; i--) {
		int to = g[v][i];
		suf[v][i + 1] = suf[v][i + 2] * (dp[to] + 1) % MOD;
	}
	for (int i = 0; i < n; i++) {
		int to = g[v][i];
		if (to == p) continue;
		long long tv = dp[v];
		long long tto = dp[to];
		dp[v] = pref[v][i] * suf[v][i + 2] % MOD;
		dp[to] = dp[to] * (dp[v] + 1) % MOD;
		calc(to, v);
		dp[v] = tv;
		dp[to] = tto;
	}
}

void solve() {
	int n; cin >> n;
	cin >> MOD;
	for (int i = 0; i < n - 1; i++) {
		int u, v; cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}	
	for (int i = 0; i <= n; i++) {
		dp[i] = 1;
	}
	dfs(1, 1);
	calc(1, 1);
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}
}

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

Measured memory_bytes: 33408
using System;
class Program
{
	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
        if (b % a == 0)
        {
            Console.WriteLine(a + b);
        }
        else {
            Console.WriteLine(b - a);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define fi first
#define se second
#define mp make_pair
int main() {


ll n,sum=1;
cin>>n;
ll a[n],b[n];
for(ll i=0;i<n;i++)
{
  cin>>a[i];
}
ll x=a[0];
for(ll i=1;i<n;i++)
{
  if(a[i]>=x)
  {
    sum++;
    x=a[i];
  }
}
cout<<sum<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int N, W;
int w[110], v[110];
int dp[110][110][310];

signed main() {
    cin >> N >> W;
    repq(i,1,N) cin >> w[i] >> v[i];
    int flr = w[1];
    repq(i,1,N) w[i] -= flr;
    int ans = 0;
    repq(i,1,N) repq(j,1,i) repq(k,0,300) {
        dp[i][j][k] = dp[i-1][j][k];
        if(k-w[i] >= 0 && k + j * flr <= W)
            dp[i][j][k] = max(dp[i][j][k], dp[i-1][j-1][k-w[i]] + v[i]);
        if(i == N) ans = max(ans, dp[i][j][k]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 27008
#include<iostream>
#include <cmath>
#include <string>
#include <iomanip>

#define loop(k) for(int i=0;i<k;i++)
#define looop(k) for(int j=0;j<k;j++)
#define swap(a,b) a^=b^=a^=b;

using namespace std;

int main(){
    int n;
    cin>>n;
    cout<<((1+n)*n)/2<<endl;
    return 0;
}

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

using namespace std;

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


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
ans=0
if a[0]==0:
    print(0)
else:
    a=a[::-1]
    ans=a[0]
    for i in a[1:]:
        ans*=i
        if ans>10**18:
            print(-1)
            break
    else:
        print(ans)

Measured memory_bytes: 21700
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<(int)c;i++)
const int inf = 1001001001; //10^9


int main() {
  string s;
  cin >> s;
  
  if(s == "AAA" || s == "BBB") cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
n, k=list(map(int, input().split()))
R, S, P= list(map(int, input().split()))
A = str(input())
U = {'r':0,'s':0,'p':0}
W = [0]*n
for i in range(k):
    U[A[i]]=U[A[i]]+1
    W[i]=1
for i in range(k, n):
    if A[i] == A[i-k]:
        if W[i-k] == 0:
            U[A[i]]=U[A[i]]+1
            W[i]=1
    else:
        U[A[i]]=U[A[i]]+1
        W[i] = 1
print(U['r']*P + U['s']*R + U['p']*S)

Measured memory_bytes: 4084
#include<iostream>
#include<string>
using namespace std;
int main(){
  int d[]={31,29,31,30,31,30,31,31,30,31,30,31};
  string s[]={"Thursday",
	      "Friday","Saturday","Sunday","Monday","Tuesday","Wednesday",};
  int i,j;
  int a,b;
  cin>>a>>b;
  while(a!=0){
    int o=0;
    for(i=1;i<a;i++) o+=d[i-1];
    o+=b-1;
    //cout << o << endl;
    cout << s[o%7] << endl;
    cin>>a>>b;
  }
  return 0;
}


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

int main(){
    string s, t;
    cin >> s >> t;
    int len = t.size();
    string ans = t.erase(len-1);
    if(s == t){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3536
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=12,M=1000006;

int d[N][N],a,b;
int x[M],y[M],c[M],m;
int mx[101][101];
bool used[101][101];

il void add(int xx,int yy,int cc){
	++m;
	x[m]=xx,y[m]=yy,c[m]=cc;
}

int main(){
//	fileio("test");
	scanf("%d%d",&a,&b);
	rep(i,1,a) rep(j,1,b) scanf("%d",d[i]+j);
	rep0(x,101) rep0(y,101){
	//	mx[x][y]=-inf;
		rep(i,1,a) rep(j,1,b){
			getmax(mx[x][y],d[i][j]-i*x-j*y);
		}
	}
/*	rep0(i,3){
		rep0(j,3) cerr<<mx[i][j]<<" ";
		cerr<<endl;
	}*/
	int s=201,t=202;
	add(s,1,inf+1);
	rep(i,1,99) add(i,i+1,inf+1);
	add(101,t,inf+2);
	rep(i,101,199) add(i+1,i,inf+2);
	rep(i,1,a) rep(j,1,b){
		bool flag=false;
		int idx,idy;
		rep0(x,101){
			rep0(y,101){
				if(d[i][j]-i*x-j*y==mx[x][y]){
					idx=x,idy=y;
					flag=true;
					break;
				}
			}
			if(flag) break;
		}
		if(!flag) return puts("Impossible"),0;
		if(used[idx][idy]) continue;
		used[idx][idy]=true;
		add(!idx?s:idx,!idy?t:idy+100,mx[idx][idy]);
	}
	puts("Possible");
	printf("202 %d\n",m);
	rep(i,1,m){
		if(c[i]<=inf) printf("%d %d %d\n",x[i],y[i],c[i]);
		else printf("%d %d %c\n",x[i],y[i],c[i]==inf+1?'X':'Y');
	}
	printf("%d %d\n",s,t);
	return 0;	
} 

Measured memory_bytes: 4480
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

#define Max 110000
int N, K;
int h[Max];
ll dp[Max];

int main(int argc, const char * argv[]) {
    N = inputValue();
    K = inputValue();
    inputArray(h, N);

    memset(dp, -1, N+1);

    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);

    repd(i, 1, N) {
        ll minimum = LL_MAX;
        repd(j, 1, min(i, K) + 1) {
            minimum = min(minimum, dp[i-j] + abs(h[i-j] - h[i]));
        }
        dp[i] = minimum;
    }

    output(dp[N-1]);

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
char s[10];
int main () {
	scanf("%s",s+1);
	if (s[1]=='S') {printf("Cloudy\n");}
	if (s[1]=='C') {printf("Rainy\n");}
	if (s[1]=='R') {printf("Sunny\n");}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  int l;
  cin >> n >> l;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    cout << v[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define I(x) cin >> x;
#define D(x) cerr << (x) << " ";
#define BR cerr << "\n";
#define P(x) cout << (x) << endl;
#define FIX cout << fixed << setprecision(10);

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll M = 0;
ll K;
ll ret = 0;

int main(void){
  
  I(M);
  I(K);

  if (K >= (1<<M)) {
    cout << -1 << endl;
    return 0;
  }
  if (M == 0) {
    cout << "0 0" << endl;
    return 0;
  }
  if (M == 1) {
    if (K == 0) {
      cout << "0 0 1 1" << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  
  FOR(i, 0, (1<<M)) {
    if (i == K) continue;
    cout << i << " ";
  }
  cout << K << " ";
  for (ll i = (1<<M)-1; i >= 0; i--) {
    if (i == K) continue;
    cout << i << " ";
  }
  cout << K << endl;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  ll N; cin >> N;
/*
  ll ok = N;    // compare(ok) is always true
  ll ng = 0;    // compare(ng) is always false
  
  while(abs(ok-ng) > 1) {
    ll mid = (ok + ng) / 2LL;
    (mid * (mid - 1) / 2 >= N - mid ? ok : ng) = mid;
  }
*/

  ll ok = 1;
  for(; ok * (ok + 1) / 2 < N; ok++);

  ll sum = 0;
  for(int i = ok - 1; i>=1; i--) {
    if(sum + i > N - ok) continue;
    printf("%d\n", i);
    sum += i;
  }

  cout << ok << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    int n,k;
    cin>>n>>k;
    for(int i=k-n+1;i<k+n;i++){
        cout<<i;
        if(i==k+n-1)cout<<endl;
        else cout<<" ";
    }
    

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int mx = 200005;
int n, a[mx], nx[mx], s = 1, t, nw[mx], f[mx];
vector<int> ans;
long long k;
int main(){
	scanf("%d%lld", &n, &k);
	rep(i,mx) f[i] = nw[i] = -1;
	rep(i,n){
		scanf("%d", a+i);
		a[i]--;
		if(nw[a[i]] != -1) nx[nw[a[i]]] = i;
		else f[a[i]] = i;
		nx[i] = f[a[i]];
		nw[a[i]] = i;
	}
	
	while(t != n){
		if(nx[t] <= t) s++;
		t = nx[t] + 1;
	}
	k %= s;
	if(k == 0) return 0*puts("");
	s = 0;t = 0;
	while(true){
		if(nx[t] <= t) s++;
		if(s == k) break;
		t = nx[t] + 1;
	}
	while(t<n){
		if(nx[t] <= t) ans.push_back(a[t]);
		else t = nx[t];
		t++;
	}
	rep(i,ans.size()) printf("%d%s", ans[i]+1, i+1==ans.size() ? "\n" : " ");
}

Measured memory_bytes: 5492
import java.util.*;

public class Main {
    static char[][] board;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        board = new char[r + 2][c + 2];
        
        for (char[] b : board) {
            Arrays.fill(b, '.');
        }
        
        for (int i = 1; i <= r; i++) {
            String str = sc.next();
            for (int j = 1; j <= c; j++) {
                board[i][j] = str.charAt(j - 1);
            }
        }
        
        boolean canClear = true;
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                if (board[i][j] == '.') continue;
                
                if (!check(i, j)) {
                    canClear = false;
                    break;
                }
            }
            
            if (!canClear) break;
        }
        
        if (canClear) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
    
    public static boolean check(int i, int j) {
        // 自身の上下左右マスに#があればtrue
        
        if (board[i - 1][j] == '#') return true;
        if (board[i + 1][j] == '#') return true;
        if (board[i][j - 1] == '#') return true;
        if (board[i][j + 1] == '#') return true;
        return false;
    }
}


Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		int[][] cards0 = {
				{1,2,3,4,5,6,7,8,9,10,11,12,13},
				{1,2,3,4,5,6,7,8,9,10,11,12,13},
				{1,2,3,4,5,6,7,8,9,10,11,12,13},
				{1,2,3,4,5,6,7,8,9,10,11,12,13}};

		int i = 0;
		int j = 1;
		int[][] cards = new int[4][13];
		for(int a = 1; a <= n; a++) {
			String index = sc.next();
			if (index.equals("S"))
				i = 0;
			else if (index.equals("H"))
				i = 1;
			else if (index.equals("C"))
				i = 2;
			else if (index.equals("D"))
				i = 3;
			j = sc.nextInt();
			cards[i][j-1] = j;
		}

		for(int ii = 0; ii < cards0.length; ii++) {
			for(int jj = 0; jj < cards0[ii].length; jj++) {
				if(cards0[ii][jj] == cards[ii][jj]) {
					cards0[ii][jj] = 0;
				}
			}
		}

		for(int ii = 0; ii < cards0.length; ii++) {
			for(int jj = 0; jj < cards0[ii].length; jj++) {
				if(cards0[ii][jj] != 0) {
					if (ii == 0)
						System.out.print("S");
					else if(ii == 1)
						System.out.print("H");
					else if(ii == 2)
						System.out.print("C");
					else if(ii == 3)
						System.out.print("D");
					System.out.println(" " + cards0[ii][jj]);
				}
			}
		}
		sc.close();
	}
}


Measured memory_bytes: 26408
#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
        int n;
        scanf("%d", &n);
        std::vector<ll> a(n);
        for(int i=0; i<n; i++) scanf("%ld", &a[i]);
        std::sort(a.begin(), a.end());

        int idx = std::upper_bound(a.begin(), a.end(), a.back()/2) - a.begin();
        ll r;
        if(a.back()-a[idx-1]*2 < a[idx]*2-a.back()) r = a[idx-1];
        else r = a[idx];
        if(r==a.back()) r = a[idx-1];
        printf("%ld %ld\n", a.back(), r);
}

Measured memory_bytes: 1024
res = ""
loop do
        m,f,r = gets.split.map {|val| val.to_i}
        if (m === -1 and f === -1 and r === -1)
                break
        elsif (m === -1 or f === -1)
                res << "F\n"
        elsif (m+f >= 80)
                res << "A\n"
        elsif (65 <= m+f and m+f < 80)
                res << "B\n"
        elsif (50 <= m+f and m+f < 65)
                res << "C\n"
        elsif (30 <= m+f and m+f < 50)
                if (50 <= r)
                        res << "C\n"
                else
                  res << "D\n"
                end
        elsif (m+f < 30)
                res << "F\n"
        end
end

print res

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll a, b, c, k, r=0;
  cin >> a >> b >> c >> k;
  if (k < a){
	r = k;
  }
  else if (k <= a + b){
	r = a;
  }
  else{
	r = a - (k - a - b);
  }
  cout << r << endl;
  
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <climits>

using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;

int main()
{
  int n;
  cin >> n;
  vector<int> x(n);
  int xmax = -1;
  int xmin = 101;
  rep(i, n)
  {
    int t;
    cin >> t;
    x[i] = t;
    xmax = max(xmax, t);
    xmin = min(xmin, t);
  }
  int ans = INT_MAX;
  for(int p = xmin; p <= xmax; ++p)
  {
    int total = 0;
    for(int j = 0; j < n; ++j)
    {
      total += (x[j] - p) * (x[j] - p);
    }
    ans = min(ans, total);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)

def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列



    S=input()
    T=input()
    flag=False
    for i,s in enumerate(S):
        if T[i]!=s:
            print('No')
            exit()
    print('Yes')

if __name__ == "__main__":
    main()

Measured memory_bytes: 68008
a,b = map(int,input().split())

mid_xor = 0
if a%2 == 0 and b%2 == 1:
    even_cnt = (b-a+1)//2
    if even_cnt%2 == 0:
        mid_xor = 0
    else:
        mid_xor = 1
    print(mid_xor)

elif a%2 == 1 and b%2 == 0:
    even_cnt = (b-1-(a+1)+1)//2
    if even_cnt%2 == 0:
        mid_xor = 0
    else:
        mid_xor = 1
    print(a^mid_xor^b)

elif a%2 == 0 and b%2 == 0:
    even_cnt = (b-a)//2
    if even_cnt%2 == 0:
        mid_xor = 0
    else:
        mid_xor = 1
    print(mid_xor^b)
    
elif a%2 == 1 and b%2 == 1:
    even_cnt = (b-a)//2
    if even_cnt%2 == 0:
        mid_xor = 0
    else:
        mid_xor = 1
    print(a^mid_xor)

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

#define ct cout
#define in cin
#define el endl
#define rep(i, N) for (int i = 0; i < N; i++)
#define ol(N) cout << N << endl

int main()
{
	int s1[4], s2[2];

	rep(i, 4){
		in >> s1[i];
	}
	in >> s2[0] >> s2[1];

	sort (s1, s1 + 4);
	reverse(s1, s1 + 4);

	ol(s1[0] + s1[1] + s1[2] + max(s2[0], s2[1]));

	return (0);
}

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

long long gcd(long long A,long long B)
{
  return B==0?A:gcd(B,A%B);
}

int main()
{
  int T;
  scanf("%d",&T);
  while(T--){
    long long A,B,C,D;
    scanf("%lld%lld%lld%lld",&A,&B,&C,&D);
    bool ans;
    if(D<B||A<B){
      ans=0;
    }
    else{
      long long g=gcd(D,B);
      long long E=A%B+(B-A%B-1)/g*g;
      ans=(E<=C);
    }
    puts(ans?"Yes":"No");
  }
  return 0;
}



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

const int MOD = 1000000007;
const int INF = 1001001001;

int main(){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    
    vi arrow = {-y2+y1, x2-x1};
    
    cout << x2+arrow[0];
    cout << " ";
    cout << y2+arrow[1];
    cout << " ";
    cout << x1+arrow[0];
    cout << " ";
    cout << y1+arrow[1];
    cout << endl;
    return 0;
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 1e6 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;

int main() {
    ll n;
    cin >> n;
    n--;
    vector<int> base26;
    while (n >= 0) {
        base26.push_back(n % 26);
        n = (ll) floor(n / 26.0) - 1;
    }
    reverse(all(base26));
    for (auto x : base26)
        cout << char(x + 'a');
}



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

int main() {
    int h, w;
    cin >> h >> w;
    vector<bool> column(h, false), row(w, false);
    vector<vector<char>> field(h, vector<char>(w));
    rep(i, h) {
        string str;
        cin >> str;
        rep(j, w) {
            field.at(i).at(j) = str.at(j);
            if(str.at(j) == '#') {
                column.at(i) = true;
                row.at(j) = true;
            }
        }
    }
    rep(i, h) {
        rep(j, w) if(column.at(i) && row.at(j)) cout << field.at(i).at(j);
        if(column.at(i)) cout << endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j,k,flag=0,ma=0,mi=0x3f3f3f3f;
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	k=(c-a)*60;
	k=(k+(d-b))-e;
	if(k<0)
	printf("0\n");
	else
	printf("%d\n",k);
} 

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

int main(){
  string a,b;
  cin>>a>>b;
  int N=(stoi(a+b));
  if(pow(N,0.5)==(int)pow(N,0.5))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    ll N, M;
    cin >> N >> M;
    vector<pll> ab(N);
    REP(i,N) cin >> ab[i].first >> ab[i].second;
    
    sort(ALL(ab));
    ll ans = 0;
    for(int i=0; M > 0;i++) {
        ans += ab[i].first * min(ab[i].second,M);
        M -= min(ab[i].second,M);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 1792