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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= 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
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  vector<string> vec;
  rep(i, n) {
    for(int j = 1; j <= 5; ++j) {
      if(i+j > n) break;
      vec.push_back(s.substr(i, j));
    }
  }
  sort(ALL(vec));
  vec.erase(unique(ALL(vec)), vec.end());
  cout << vec[k-1] << endl;
}

Measured memory_bytes: 4332
/******************************************************************************

рассвет.

*******************************************************************************/
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define all(a) (a).begin(),(a).end()
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int>
#define vplli vector <pair <lli,lli> >
#define vvi vector <vector <int> >
#define vvlli vector <vector <lli> >
#define vvpii vector <vector <pair <int,int>> >
#define fr(i,n) for (int i = 0; i < (n); ++i)
#define frbig(i,n) for (lli i = 0; i < (n); ++i)
#define fra(i,a,n) for (lli i = a; i < (n); ++i)
#define run(c,s) for(auto c:s)
#define read(n) int n; cin >> n;
#define readchar(n) char n; cin >> n;
#define readstr(n) string n; cin >> n;
#define readarr(a,n) fr(i,n) cin >> a[i];
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;

const lli MOD=1e9+7;
const lli MAXN=5e4+1;
const ld PI=acos(-1);

int main(){
    rapgame
    //freopen("bridges.in", "r", stdin);
    //freopen("bridges.out", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        read2(l,r);read(n);
        int ans=0;
        for(int i=l;i<=r;i++){
            if(i%n==0){
                ++ans;
            }
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 3648
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
/*
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 JENISH MONPARA S.      IIT PATNA      ADITI GOEL IS LOVE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// while(scanf("%d",&n)!=EOF)


#include <bits/stdc++.h>
#define ii int64_t
#define PI 3.14
#define lli long long int
#define li long int
#define deb(x) cout<<"\nhi"<<x<<"\n"
#define mod 1000000007
#define f(x,n) for(int x=0;x<n;++x)
#define ff(x,y,z) for(x=y;x<=z;++x)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;


int main()
 
{
    ios;
    int n,i,j;
    double dp[3000]={0},p,ans=0;
    cin>>n;
    dp[0]=1;
    for(i=1;i<=n;i++)
    {
        cin>>p;
        for(j=i;j>0;--j)
            dp[j]=dp[j-1]*p+dp[j]*(1-p);
        dp[0]*=(1-p);

    }for(i=n/2+1;i<=n;i++)ans+=dp[i];
    cout<<setprecision(9)<<fixed<<ans;
    

}





Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int h,w;
	int i,j;
	refrain:
	scanf("%d %d",&h,&w);
	if(h==0&&w==0){
		return 0;
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			printf("#");
		}
		printf("\n");
	}
	printf("\n");
	goto refrain;
}

Measured memory_bytes: 572
/*
ex 7_1
tomatokan
*/

#include <stdio.h>

typedef struct point{
    int x_elem;
    int y_elem;
}point;

point new_point(int x_elem,int y_elem){
    point new_p={x_elem,y_elem};
    return new_p;
}

point shift_point(point old,int shift_x,int shift_y){
    return new_point(old.x_elem+shift_x,old.y_elem+shift_y);
}

point add_as_complex(point point1,point point2){
    return shift_point(point1,point2.x_elem,point2.y_elem);
}

point mult_by_int_as_complex(point old,int times){
    return new_point(old.x_elem*times,old.y_elem*times);
}

point mult_as_complex(point point1,point point2){
    return new_point(point1.x_elem*point2.x_elem-point1.y_elem*point2.y_elem, point1.x_elem*point2.y_elem+point1.y_elem*point2.x_elem);
}

int main(void){
    int read1,read2;
    point vertex1,vertex2,vertex3,vertex4;
    point vector_1to2;
    point vector_2to3;
    scanf("%d",&read1);
    scanf("%d",&read2);
    vertex1=new_point(read1,read2);
    scanf("%d",&read1);
    scanf("%d",&read2);
    vertex2=new_point(read1,read2);
    vector_1to2=add_as_complex(vertex2,mult_by_int_as_complex(vertex1,-1));
    vector_2to3=mult_as_complex(vector_1to2,new_point(0,1));
    vertex3=add_as_complex(vertex2,vector_2to3);
    vertex4=add_as_complex(vertex1,vector_2to3);
    printf("%d %d %d %d\n",vertex3.x_elem,vertex3.y_elem,vertex4.x_elem,vertex4.y_elem);
    return 0;
}

Measured memory_bytes: 1696
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int>
using namespace std;

inline void solve(){
    int n; cin>>n; 
    vi  a(n+1);
    for (int i=1;i<=n;i++) cin >> a[i];
    a[1]--; bool ok=true;
    for (int i=2;i<=n;i++){
        if (a[i]<a[i-1]) ok=false;
        if (a[i]-1>=a[i-1]) a[i]--;
    }
    if (ok) cout << "Yes" << endl; 
    else cout << "No" << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 4016
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

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

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

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int k,x;
	cin>>k>>x;
	for (int i = x-k+1; i <= x+k-1 ; i++){
		cout<<i<<" ";
	}cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,b;
    cin>>n;
    vector<int> a(100010);
    rep(i,n){
        cin>>b;
        if(b!=0) a[b-1]++;
        a[b]++;
        a[b+1]++;
    }
    sort(all(a));
    reverse(all(a));
    cout<<a[0];
}

Measured memory_bytes: 3728
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};
use std::collections::VecDeque;

fn main() {
    let k: i64 = read();
    let mut q: VecDeque<i64> = VecDeque::new();
    let mut cnt = 0;
    for i in 1..10 {
        q.push_back(i);
    }
    let mut ppd = 0;

    for _ in 0..k {
        ppd = q.pop_front().unwrap();
        if ppd % 10 != 0 {
            q.push_back(10 * ppd + ppd % 10 - 1);
        }
        q.push_back(10 * ppd + ppd % 10);
        if ppd % 10 != 9 {
            q.push_back(10 * ppd + ppd % 10 + 1);
        }
    }

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


Measured memory_bytes: 6396
#include <stdio.h>          // printf(), scanf()

int
main(int argc, char** argv)
{
	int a, b;

	scanf("%d %d", &a, &b);
	if (a < b)
		printf("a < b\n");
	else if (a > b)
		printf("a > b\n");
	else
		printf("a == b\n");

	return 0;
}

Measured memory_bytes: 580
#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  bool a = false, b = false;
  for (auto c : s) {
    if (c == 'A') {
      a = true;
    }
    if (c == 'B') {
      b = true;
    }
  }

  if (a && b) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define MAX 1000001
#define INF (1<<29)

int main(){
  int pos[MAX];
  int x,y;

  while(true){
    cin >> x >> y;
    if(x == 0 && y == 0) break;
    fill(pos,pos+MAX,INF);
    int a,b;
    for(int i = 0 ; ; i++){
      x %= y;
      if(x == 0){
        a = i;
        b = 0;
        break;
      }
      if(pos[x] != INF){
        a = pos[x];
        b = i - pos[x];
        break;
      }
      pos[x] = i;
      x *= 10;
    }
    cout << a << " " << b << endl;
  }

  return 0;
}

Measured memory_bytes: 5064
#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)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int main()
{
    int N;
    cin >> N;
    unordered_set<int> S;
    rep(i, N)
    {
        int a;
        cin >> a;
        S.insert(a);
    }
    S.size() == N ? cout << "YES" : cout << "NO";

    return 0;
}

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

int arr[100100], dp[100100];

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> arr[i];

  dp[0] = 0;
  for (int i = 1; i < n; ++i) dp[i] = 2e9;

  for (int pos = 1; pos < n; ++pos) {
    for (int step = 1; step <= k; ++step) {
      if ( pos - step < 0 ) break;
      dp[pos] = min( dp[pos], dp[pos - step] + abs(arr[pos] - arr[pos - step]) );
    }
  }
  
  cout << dp[n - 1] << endl;
  return 0;
}

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

namespace ProblemD
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = GetLong();
            var tablef = new long[N + 1];
            for(int i = 1; i <= N; i++)
            {
                long temp = 0;
                temp += i;
                while(temp <= N)
                {
                    tablef[temp]++;
                    temp += i;
                }
            }
            long ans = 0;
            for(int i = 1; i<= N; i++)
            {
                ans += tablef[i] * i;
            }

            Console.WriteLine(ans);
        }
        public static int GetInt() => int.Parse(Console.ReadLine());
        public static int[] GetIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static double[] GetDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray();
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static long[] GetLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray();

    }
}


Measured memory_bytes: 105564
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoderBeginner116
{
    class A_RightTriangle
    {
        static void Main(string[] args)
        {
            string[] inputString = Console.ReadLine().Split(' ');

            var lines = new List<int>();

            lines.Add(int.Parse(inputString[0]));
            lines.Add(int.Parse(inputString[1]));
            lines.Add(int.Parse(inputString[2]));

            // 昇順ソート
            var sortedLines = lines
                                .OrderBy(x => x)
                                .ToList();

            // 面積を求めて数値に変換
            string msg = (sortedLines[0] * sortedLines[1] / 2).ToString();

            Console.WriteLine("{0}", msg);
        }
    }
}


Measured memory_bytes: 13396
import sys
input = sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

def main():
    N,M,L = map(int,input().split())
    edge = np.zeros((N,N))
    for _ in range(M):
        a,b,c = map(int,input().split())
        edge[a-1][b-1] = edge[b-1][a-1] = c
        
    length = floyd_warshall(edge,directed=False)
    ref = np.where(length<=L,1,0)
    ans = floyd_warshall(ref,directed=False)
    Q = int(input())
    for _ in range(Q):
        s,t = map(int,input().split())
        if ans[s-1][t-1] == float("inf"):
            print(-1)
        else:
            print(int(ans[s-1][t-1])-1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 17848
use proconio::{fastout, input};
use rand::prelude::*;
use std::cmp::Ordering;

pub fn quicksort<T, R>(a: &mut [T], rng: &mut R)
where
    T: Ord,
    R: Rng + ?Sized,
{
    quicksort_impl(a, rng);
}

fn quicksort_impl<T, R>(a: &mut [T], rng: &mut R)
where
    T: Ord,
    R: Rng + ?Sized,
{
    let n = a.len();
    if n <= 1 {
        return;
    }
    let mut r = rng.gen_range(0, n);
    let mut p = 0;
    let mut j = 0;
    let mut q = n;
    while j < q {
        match a[j].cmp(&a[r]) {
            Ordering::Less => {
                a.swap(j, p);
                if r == p {
                    r = j;
                } else if r == j {
                    r = p;
                }
                p += 1;
                j += 1;
            }
            Ordering::Equal => {
                j += 1;
            }
            Ordering::Greater => {
                q -= 1;
                a.swap(j, q);
                if r == q {
                    r = j;
                } else if r == j {
                    r = q;
                }
            }
        }
    }
    quicksort_impl(&mut a[..p], rng);
    quicksort_impl(&mut a[q..], rng);
}

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [i64; n],
    }
    a.sort();
    if a[0] == 0 {
        println!("0");
        return;
    }
    let mut prod = 1;
    for x in a {
        if prod > 1_000_000_000_000_000_000 / x {
            println!("-1");
            return;
        }
        prod *= x;
    }
    println!("{}", prod);
}


Measured memory_bytes: 5020
#include<iostream>
#include<cstdio>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=500500,P=998244353;
int n,K,ans,iv[N],vf[N],fc[N];
int C(int x,int y){return 1ll*fc[x]*vf[x-y]%P*vf[y]%P;}
int main(){
	scanf("%d%d",&n,&K);
	iv[1]=fc[0]=vf[0]=1;
	FOR(i,2,K) iv[i]=1ll*iv[P%i]*(P-P/i)%P;
	FOR(i,1,K) fc[i]=1ll*fc[i-1]*i%P,vf[i]=1ll*vf[i-1]*iv[i]%P;
	FOR(i,n,K) (ans+=C(K-1,i-1))%=P;
	cout<<ans<<'\n'; 
} 

Measured memory_bytes: 6144
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    d = collections.defaultdict(int)
    lstr = "1"
    for i in range(n):
        w = str(readline().rstrip().decode('utf-8'))
        if (w[0] == lstr or lstr == "1") and w not in d:
            d[w]
            lstr = w[-1]
        else:
            print("No")
            exit()
    print("Yes")


if __name__ == '__main__':
    solve()


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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }
    if(n == 2){
        if(s[0] == s[1]){
            cout << 1 << endl;
        }
        else{
            cout << 2 << endl;
        }
        return 0;
    }
    int dp[n]{0};
    dp[0] = 1;
    if(s[0] == s[1]){
        dp[1] = 1; 
    }
    else{
        dp[1] = 2;
    }
    if(s[0] != s[1] && s[1] != s[2]){
        dp[2] = 3;
    }
    else{
        dp[2] = 2;
    }
    for(int i = 3;i < n;i++){
        if(s[i-1] == s[i]){
            dp[i] = dp[i-3] + 2;
        }
        else{
            dp[i] = dp[i-1] + 1;
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1412
import heapq
n,m,s,t=list(map(int, input().strip().split()))
links_y=[[]for i in range(n) ]
links_s=[[]for i in range(n) ]
INF=float('inf')
for i in range(m):
    u,v,a,b=list(map(int, input().strip().split()))
    links_y[u-1].append((v-1,a))
    links_y[v-1].append((u-1,a))
    links_s[u-1].append((v-1,b))
    links_s[v-1].append((u-1,b))

def dijkstra(frm, links):
    dist=[INF]*n
    dist[frm]=0
    Q=[(0,frm)]
    heapq.heapify(Q)
    while Q:
        d,u = heapq.heappop(Q)
        for v,dd in links[u]:
            if dist[v]> d+dd:
                dist[v]=dd+d
                heapq.heappush(Q,(dist[v],v))
    return dist
yen_cost=dijkstra(s-1,links_y)
snk_cost=dijkstra(t-1,links_s)
sumyensnk=[i+j for i,j in zip(yen_cost,snk_cost)]
min_snk=[INF]*n
tmp=INF
for i in range(n)[::-1]:
    min_snk[i] = min(sumyensnk[i],tmp)
    tmp = min_snk[i]
money=10**15
for sumsnk in min_snk:
    print(money-sumsnk)

Measured memory_bytes: 91956
raws, columns = map(int, input().strip().split())
a = []
for i in range(raws):
    a.append(list(map(int, input().strip().split())))
for i in range(raws):
    a[i].append(sum(a[i]))
a.append([sum(i) for i in zip(*a)])
for r in a:
    print(' '.join(str(x) for x in r))

Measured memory_bytes: 7768
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


void solve(long long A, long long B, long long T){
    cout<< B*floor((T+0.5)/A)<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long T;
    scanf("%lld",&T);
    solve(A, B, T);
    return 0;
}


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

#define inf 0x3f3f3f3f
#define pi acos(-1)
#define fi first
#define se second
#define pb push_back
#define int long long
#define all(a) a.begin(),a.end()
template<class T> bool mmin(T &a,T b){return (a>b ?(a=b,true):false);};
template<class T> bool mmax(T &a,T b){return (a<b ?(a=b,true):false);};

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int w,h,x,y,ans=0;
	cin >> w >> h >> x >> y;
	double a = w*h;
	a/=2.0;
	cout << fixed << setprecision(7) << a << " " << (2*x==w and 2*y==h) << '\n';
	
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}




















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

using namespace std;

const int MAXN = 110;
int N, W;
long long int A[MAXN], P[MAXN];
map<long long int, long long int >dp;
deque<pair<long long int, long long int > > buffer;
long long int calcDP(){
	for(int i = 0;i < N;i++){
		map<long long int, long long int>::reverse_iterator it = dp.rbegin();
		for(;it!=dp.rend();it++){
			long long int weight = it->first;
			long long int value = it->second;
			if(weight+P[i]<=W && dp[weight]+A[i]>dp[weight+P[i]])
				buffer.push_back({weight+P[i],dp[weight]+A[i]});
		}
		dp[P[i]]=A[i];
		while(!buffer.empty()){
			dp[buffer.front().first]=buffer.front().second;
			buffer.pop_front();
		}
		map<long long int, long long int>::iterator firstIt = dp.begin();
		firstIt++;
		map<long long int, long long int>::iterator secondIt = dp.begin();
		for(;firstIt!=dp.end();){
			if(firstIt->second<=secondIt->second){
				map<long long int, long long int>::iterator tmp = firstIt;
				firstIt++;
				dp.erase(tmp);
			}
			else
				firstIt++,secondIt++;
		}
	}
	long long int sol = 0;
	for(auto adj : dp){
		sol = max (sol, adj.second);
	}
	return sol;
}

int main(){
	cin>>N>>W;
	for(int i=0;i<N;i++)
		cin>>P[i]>>A[i];
	cout<<calcDP();	
}

Measured memory_bytes: 512
n,k = map(int,input().split())
d = {}
for _ in range(n):
    a,b = map(int,input().split())
    if not a in d:
        d[a] = b
    else:
        d[a] += b

c = 0
for v in sorted(d.items()):
    c += v[1]
    if k <= c:
        print (v[0])
        exit ()


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

int main(void) {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    if (k % 2 == 0) {
        cout << a - b << endl;
    } else {
        cout << b - a << endl;
    }
    return 0;
}

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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void Main() {
    int a,b,c;
    cin>>a>>b>>c;
    if (b - a == c - b) {
        cout << "YES" << endl;
    } else cout << "NO" << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>
#define Graph vector<vector<int>>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void func(long long L) {}

int main() {
  // cout << fixed << setprecision(5);

  long long L;
  scanf("%lld", &L);
  long double N = static_cast<long double>(L);

  cout << fixed << setprecision(15)<< N*N*N/27.0000000000 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  ll A,B;
  int K;
  cin >> A >> B >> K;
  if(B-A+1<=2*K){
    for(ll i=A;i<=B;++i) cout << i << endl;
  }
  else{
    for(ll i=A;i<A+K;++i) cout << i << endl;
    for(ll i=B-K+1;i<=B;++i) cout << i << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3612
#define CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<math.h>
#include<vector>
#include<utility>
#include<functional>
#include<iostream>
#define sqr(x) x*x
const int INF = 100000000;
bool flg=false;
using namespace std;
typedef pair<int, int>P;


int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x,a,b;
	cin >> x >> a >> b;
	x -= a;
	x %= b;
	cout << x << endl;
	return 0;
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	map<string, int> mp;
	int ans = 0;
	for (string s; n--; )
	{
		cin >> s;
		ans = max(ans, ++mp[s]);
	}
	for (auto i : mp)
		if (i.S == ans)
			cout << i.F << "\n";

	return 0;
}


Measured memory_bytes: 23808
import java.util.*;
import java.math.*;
public class Main{

    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        double b = sc.nextDouble();
        BigDecimal c = new BigDecimal(a);
        BigDecimal d = BigDecimal.valueOf(b);
        System.out.println(c.multiply(d).toBigInteger());
    }
}

Measured memory_bytes: 37776
/**
 *    author:  zjsdut
 *    created: 2020/03/28 20:27:07
 **/
#include <bits/stdc++.h>

using namespace std;

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

template <typename A, typename B> bool chkmin(A &a, const B &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

template <typename A, typename B> bool chkmax(A &a, const B &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> istream &operator>>(istream &stream, vector<T> &vec) {
  for (auto &x : vec)
    stream >> x;
  return stream;
}

void scan() {}

template <class T, class... Args> void scan(T &a, Args &... rest) {
  cin >> a;
  scan(rest...);
}

using ll = long long;
using vl = vector<ll>;
using vb = vector<bool>;
using vi = vector<int>;
using pii = pair<int, int>;
template <typename T> using vv = vector<vector<T>>;
#define rng(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define up(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define down(i, b, a) for (int i = int(b); i >= int(a); i--)
#define TOKENPASTE(x, y) x##y
#define TOKENPASTE2(x, y) TOKENPASTE(x, y)
#define rep(n)                                                                 \
  for (int TOKENPASTE2(_iter_, __LINE__) = 0,                                  \
                               TOKENPASTE2(_num_, __LINE__) = (int)(n);        \
       TOKENPASTE2(_iter_, __LINE__) < TOKENPASTE2(_num_, __LINE__);           \
       ++TOKENPASTE2(_iter_, __LINE__))
#define FOR(x, cont) for (const auto &x : cont)
#define For(x, cont) for (auto &x : cont)
#define all(x) begin(x), end(x)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define SZ(x) (int)(x).size()
#define UNIQ(vec) (vec).erase(unique(all(vec)), end(vec))
#define LB(cont, x) int(lower_bound(all(cont), x) - begin(cont))
#define UB(cont, x) int(upper_bound(all(cont), x) - begin(cont))

template <typename T>
ostream &operator<<(ostream &stream, const vector<T> &vec) {
  if (!vec.empty()) {
    stream << vec[0];
    for (size_t i = 1; i != vec.size(); ++i)
      stream << ' ' << vec[i];
  }
  return stream;
}

template <typename T> void print(const vector<T> &t) { cout << t << '\n'; }

template <typename T> void print(const vector<vector<T>> &t) {
  for (const auto &row : t) {
    print(row);
  }
}

template <typename T> void print(const T &t) { cout << t << ' '; }

template <typename T, typename... Args>
void print(const T &t, const Args &... rest) {
  print(t);
  print(rest...);
}

template <typename T> void println(const T &t) { cout << t << '\n'; }

template <typename T, typename... Args>
void println(const T &t, const Args &... rest) {
  print(t);
  println(rest...);
}

int main() {
#if defined LOCAL && !defined DUIPAI
  ifstream in("in.txt");
  cin.rdbuf(in.rdbuf());
#endif
  ll x;
  scan(x);
  println(x / 500 * 1000 + x % 500 / 5 * 5);
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int[] a = new int[N];
    long sum = 0;
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      sum += a[i];
    }
    int[][] b = new int[M][2];
    for (int i = 0; i < M; i++) b[i] = new int[] { scanner.nextInt(), scanner.nextInt() };

    Arrays.sort(a);
    Arrays.sort(b, Comparator.comparingInt(b2 -> -b2[1]));

    int i = 0;
    for (int j = 0; j < M && i < N; j++)
      for (int k = 0; k < b[j][0] && i < N && a[i] < b[j][1]; k++, i++) {
        sum -= a[i];
        sum += b[j][1];
      }
    System.out.println(sum);
  }
}


Measured memory_bytes: 98664
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    B.reverse()
    l, r = 0, N - 1

    for i in range(N):
        if A[i] != B[i]:
            continue
        if l < i and A[i] != B[l] and A[l] != B[i]:
            B[l], B[i] = B[i], B[l]
            l += 1
            continue
        if i < r and A[i] != B[r]:
            B[i], B[r] = B[r], B[i]
            r -= 1
            continue
        return None
    return B

t = main()
if t is None:
    print('No')
else:
    print('Yes')
    print(' '.join(map(str, t)))


Measured memory_bytes: 40144
import math
while True:
    n = int(input())
    if n == 0: break
    s = list(map(int,input().split()))
    dis = 0
    mean = sum(s)
    mean /= n
    for s in s:
        dis += (s-mean)**2
    print('{0:.5f}'.format(math.sqrt(dis/n)))
    



Measured memory_bytes: 5692
s = list(input())

def get_reversed_str(s):
	return list(reversed(s))

reversed_s = get_reversed_str(s)

count = 0
if s != reversed_s:
	for i in range(len(s)):
		if s[i] != reversed_s[i]:
			s[i] = reversed_s[i]

			count += 1
			if s != get_reversed_str(s):
				continue
			else:
				break
print(count)

Measured memory_bytes: 38512
// C++ program to replace space with - 

#include <cstring> 
#include <iostream> 
using namespace std; 

int main() 
{ 
	string str;
getline(cin,str);
	for (int i = 0; i < str.length(); ++i) { 
		if (str[i] ==',') { 

			str[i] = ' '; 
		} 
	} 

	cout << str << endl; 

	return 0; 
} 


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
		int d = stdIn.nextInt();
		
		if (a - b > 0) {
			if (c - d > 0) {
				System.out.println(b + d);
			} else {
				System.out.println(b + c);
			}
		} else {
			if (c - d > 0) {
				System.out.println(a + d);
			} else {
				System.out.println(a + c);
			}
		}
	}
}

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

#define ll  long long
#define PII pair<ll,ll>
#define VI  vector<ll>
#define VB  vector<bool>
#define VC vector<char>
#define VVI vector<vector<ll>>
#define VVC vector<vector<char>>
#define VS  vector<string>
#define VP  vector<PII>
#define lf(i,a,b) for(ll i=a;i<=b;i++)
#define lr(i,a,b) for(ll i=a;i>=b;i--)
#define lfl(i,v) for(ll i=0;i<v.size();i++)
#define lrl(i,v) for(ll i=(ll)(v.size())-1;i>=0;i--)
#define chk2(a,b) cout<<"check :  "<<a<<" "<<b<<endl
#define chk3(a,b,c) cout<<"check :  "<<a<<" "<<b<<" "<<c<<endl
#define chk4(a,b,c,d) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define chk5(a,b,c,d,e) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl
#define l_b(v,k)  lower_bound(v.begin(),v.end(),k)-v.begin()
#define u_b(v,k)  upper_bound(v.begin(),v.end(),k)-v.begin()
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define p_b push_back
#define p_f push_front
#define m_p make_pair
#define fir first
#define sec second
#define sz size()
ll n,m,k;
VVI v;
ll dp[22][4000000];
ll fun(ll ind,ll bm)
    {   if(ind>n)
            return 1;
        if(dp[ind][bm]!=-1)
            return dp[ind][bm]; 
        ll sum=0;
        lf(i,0,n-1)
        {   if(v[ind][i+1])
            {   if((bm&(1<<i))==0)
                {   sum=(sum+fun(ind+1,bm|(1<<i)))%mod;}
            }
        }
        return dp[ind][bm]=sum;
    }
int main() 
{   cin>>n;
    v=VVI(n+1,VI(n+1,0));
    lf(i,1,n)
        lf(j,1,n)
            cin>>v[i][j];
    memset(dp,-1,sizeof(dp));
    cout<<fun(1,0)<<endl;;
}

Measured memory_bytes: 687744
import java.lang.StringBuilder
import kotlin.math.*

typealias Num = Int

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}

fun <T> MutableList<T>.removeLast() = this.removeAt(this.lastIndex)

const val mod = 998244353L

fun binarySearch(ok:Num,ng:Num,eps:Num,f:(Num)->Boolean):Num {
	var _ok = ok
	var _ng = ng
	while(abs(_ok-_ng)>eps) {
		val mid = (_ok+_ng)/2
		if(f(mid))
			_ok = mid
		else
			_ng = mid
	}
	return _ok
}

fun main() {
	abc000X()
}

fun abc000X() {
	for(n in 1..int()) {
		var r = 0L
		for(x in 1..n) {
			val m = n-x*x
			if(m<2*x+3)
				break

			for(y in x..m) {
				val o = m-y*y-x*y
				if(o<x+y+1)
					break

				val z = binarySearch(y,o,1) {z-> z*z+x*z+y*z<=o}
				if(z*z+x*z+y*z==o) {
					when {
						x==y&&y==z->++r
						x==y||y==z||z==x->r += 3
						else->r += 6
					}
				}
			}
		}
		println(r)
	}
}


Measured memory_bytes: 53720
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(a, b) for(int unsafe_cnt=a; unsafe_cnt < b;unsafe_cnt++)
#define fn auto
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
void iput(int input) {put(input);}

fn main() -> int {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (2*b - a == c ? "YES" : "NO")  << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        int ans=0;
        if(N<10)ans=N;
        else if(N<100)ans=9;
        else if(N<1000)ans=9+N-99;
        else if(N<10000)ans=909;
        else if(N<100000)ans=909+N-9999;
        else ans=90909;
        Console.WriteLine(ans);
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public static void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }//Answer.IntArrayAns(x);
    public static void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}


Measured memory_bytes: 11092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
 
public class Main {
	private static  BufferedReader  br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	* @param args
	*/
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int cnt = parseNum();
		while (cnt-- > 0) {
			parseSnake();
		}
	}

	private static void parseSnake() {
		int     typ = 0;
		String  str = null;

		if ((str = parseStdin()) != null) {
			int	len = str.length();
			if (len >= 6 && len%2 == 0) {
				if (str.charAt(0) == '>') {
					if (str.charAt(1) == '\'') {
						if (str.charAt(len-1) == '~' && str.charAt(len-2) == '=') {
							if (str.charAt(2) == '=') {
								char	stc = 0;
								int		mid = 2+(len-4)/2;
								for (int i = 2; i < len-1; i++) {
									stc = str.charAt(i);
									typ = (i == 2) ? 1 : typ;
									if ((stc != '=' && stc != '#') || (stc == '#' && i != mid) || (stc != '#' && i == mid)) {
										typ = 0;
										break;
									}
								}
							}
						}
					}
					else if (str.charAt(1) == '^') {
						if (str.charAt(len-1) == '~' && str.charAt(len-2) == '~' && str.charAt(len-3) == '=') {
							char	sc1 = 0;
							char	sc2 = 0;
							for (int i = 2; i+1 < len-2; i += 2) {
								typ = (i == 2) ? 2 : typ;
								sc1 = str.charAt(i);
								sc2 = str.charAt(i+1);
								if (sc1 != 'Q' || sc2 != '=') {
									typ = 0;
									break;
								}
							}
						}
					}
				}
			}
		}

		switch (typ) {
		case	1:
			System.out.println("A");
			break;
		case	2:
			System.out.println("B");
			break;
		default:
			System.out.println("NA");
			break;
		}
	}

	private static int parseNum() {
		int     num = 0;
		String  str = null;

		if ((str = parseStdin()) != null) {
			num = Integer.parseInt(str);
		}

		return num;
	}

	private static String parseStdin() {
		String  stdin = null;

		try {
			String  tmp = br.readLine();
			if (tmp != null) {
				if (!tmp.isEmpty()) stdin = tmp;
				}
			}
		catch (IOException e) {}

		return stdin;
	}
}

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

const long long maxn = 3e3 + 10;
const long long mod = 998244353;

long long ans;
long long n, s;
long long a[maxn];
long long sum[maxn];
long long dp[maxn][maxn];

void in();
void solve();
void out();

int main(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    in();
    solve();
    out();
}

void in(){
    cin >> n >> s;
    for(long long i = 0; i < n; i++)
        cin >> a[i];
}

void solve(){
    dp[0][0] = 1;
    for(long long i = 1; i <= n; i++){
        for(long long j = 0; j <= s; j++){
            dp[i][j] = dp[i - 1][j];
            if(j - a[i - 1] >= 0)
                dp[i][j] += dp[i - 1][j - a[i - 1]];
            dp[i][j] %= mod;
        }
    }
    for(long long i = 0; i <= s; i++){
        for(long long j = 0; j <= n; j++){
            sum[i] += dp[j][i];
            sum[i] %= mod;
        }
    }
    for(long long i = 0; i < n; i++){
        ans += sum[s];
        ans %= mod;
        sum[0]--;
        for(long long j = 1; j <= s; j++){
            if(j - a[i] >= 0){
                sum[j] = (sum[j] - sum[j - a[i]] + mod) % mod;
            }
        }
    }
}

void out(){
    cout << ans;
}


Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

#define PT pair<int, int>

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


	int N, M;
	cin >> N >> M;
	vector<int> E[300000];
	rep(i, M) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		E[u].pb(v + 100000);
		E[u + 100000].pb(v + 200000);
		E[u + 200000].pb(v);
	}
	int S, T;
	cin >> S >> T;
	S--;
	T--;

	int D[300000];
	rep(i, 300000) D[i] = 1e9;
	D[S] = 0;

	priority_queue<PT, vector<PT>, greater<PT>> que;
	que.push(mp(0, S));
	while (que.size()) {
		PT p = que.top();
		que.pop();
		int i = p.second;
		if (D[i] != p.first) continue;
		for (int p2 : E[i]) {
			int d = D[i] + 1;
			if (D[p2] > d) {
				D[p2] = d;
				que.push(mp(d, p2));
			}
		}
	}

	if (D[T] == 1e9) co(-1);
	else co(D[T] / 3);

	Would you please return 0;
}

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

public class Main {

	public static String decode (String code) {
		String ret = "";
		for (int i = 0; i < code.length(); i++) {
			if (code.charAt(i) == '@') {
				int lim = code.charAt(i + 1) - '0';
				char c = code.charAt(i + 2);
				for (int j = 0; j < lim; j++)
					ret += c + "";
				i += 2;
			} else {
				ret += code.charAt(i) + "";
			}
		}
		return ret;
	}

	public static void main(String[] args) throws IOException {

		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null) {
			System.out.println(decode(line));
			line = null;
		}

	}

}

Measured memory_bytes: 17044
import collections
S = input()[::-1]
N = len(S)
mod = [1] * N
#mod[i]=S[i]*10**i % 2019
for i in range(1, N):
    mod[i] = mod[i - 1] * 10 % 2019
for i in range(N):
    mod[i] *= int(S[i])
cumsum = [0] * N
cumsum[0] = mod[0]
for i in range(1, N):
    cumsum[i] = (cumsum[i - 1] + mod[i]) % 2019
cnt = collections.Counter(cumsum)
ans = cnt[0]
for i in range(2019):
    c = cnt[i]
    ans += c * (c - 1) // 2
print(ans)


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

using ll = long long;
using namespace std;

string s;

void input(){
  cin >> s;
}

void solver(){
  ll cnt1 = 0;
  ll cnt0 = 0;
  for(int i = 0; i < s.length(); ++i){
    if(s[i] == '0'){
      cnt0++;
    }else{
      cnt1++;
    }
  }
  cout<< 2 * min(cnt1, cnt0) << endl;
}

int main(){
  input();
  solver();
}

Measured memory_bytes: 512