akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	int s=0;;
	for (int i=1;i<=n;i++)
	{
		int p=i,k=0,q;
		while (p!=0)
		{
			q=p%10;
			p/=10;
			k+=q;
		}
		if (k>=a && k<=b) 
		  s+=i;
	}
	cout<<s<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
    
typedef long long ll;
typedef unsigned long long ull;
    
#define MOD 1000000007
#define mi 1000000000

int max3(int a,int b,int c)
{
    if(a>=b&&a>=c)
        return a;
    else if(b>=a&&b>=c)
        return b;
    else if(c>=a&&c>+b)
        return c;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];
    for(int i=1;i<n;i++)
    {
        a[i]+=max(b[i-1],c[i-1]);
        b[i]+=max(a[i-1],c[i-1]);
        c[i]+=max(b[i-1],a[i-1]);
    }
    cout<<max3(a[n-1],b[n-1],c[n-1]);
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int ans=0;
  vector<int> snake(n);
  for(int i=0;i<n;i++){
    cin>>snake[i];
  }
  sort(snake.rbegin(),snake.rend());
  for(int i=0;i<k;i++){
    ans+=snake[i];
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

typedef vector <string> VS;
typedef pair <int, int> PII;
typedef pair <PII, PII> PPP;
typedef set <PPP> SPPP;

int R, C;
VS P;
SPPP M;

bool dfs( int a, int m, int x, int y ) {
  int na = a, nm = m, nx = x, ny = y;
  char op = P[y][x];

  // check
  PPP q( PII( a, m ), PII( x, y ) );
  if ( M.find( q ) != M.end() ) {
    return false;
  }
  M.insert( q );
  
  // operation
  if ( op == '<' ) {
    na = 0;
  } else if ( op == '^' ) {
    na = 1;
  } else if ( op == '>' ) {
    na = 2;
  } else if ( op == 'v' ) {
    na = 3;
  } else if ( op == '_' ) {
    if ( m == 0 ) {
      na = 2;
    } else {
      na = 0;
    }
  } else if ( op == '|' ) {
    if ( m == 0 ) {
      na = 3;
    } else {
      na = 1;
    }
  } else if ( op == '?' ) {
    for ( int i = 0; i < 4; i++ ) {
      na = i;
      int nnx = x, nny = y;
      // move
      if ( na == 0 ) {
	nnx--;
      } else if ( na == 1 ) {
	nny--;
      } else if ( na == 2 ) {
	nnx++;
      } else if ( na == 3 ) {
	nny++;
      }

      if ( nnx >= C ) {
	nnx = 0;
      } else if ( nnx < 0 ) {
	nnx = C - 1;
      }
      if ( nny >= R ) {
	nny = 0;
      } else if ( nny < 0 ) {
	nny = R - 1;
      }

      if ( dfs( na, nm, nnx, nny ) ) return true;
    }
    return false;
  } else if ( op == '.' ) {
    // empty
  } else if ( op == '@' ) {
    return true;
  } else if ( op >= '0' && op <= '9' ) {
    nm = (int)( op - '0' );
  } else if ( op == '+' ) {
    nm = ( nm + 1 ) % 16;
  } else if ( op == '-' ) {
    nm = ( nm - 1 ) % 16;
  }

  // move
  if ( na == 0 ) {
    nx--;
  } else if ( na == 1 ) {
    ny--;
  } else if ( na == 2 ) {
    nx++;
  } else if ( na == 3 ) {
    ny++;
  }

  if ( nx >= C ) {
    nx = 0;
  } else if ( nx < 0 ) {
    nx = C - 1;
  }
  if ( ny >= R ) {
    ny = 0;
  } else if ( ny < 0 ) {
    ny = R - 1;
  }

  if ( dfs( na, nm, nx, ny ) ) return true;
  return false;
}

int main( void ) {
  cin >> R >> C;
  for ( int i = 0; i < R; i++ ) {
    string line;
    cin >> line;
    P.push_back( line );
  }
  bool result = dfs( 2, 0, 0, 0 );
  cout << ( result ? "YES" : "NO" ) << endl;
  return 0;
}

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

using ll=long long;
int main(){
    int x,y,z;
    cin>>x>>y>>z;
    int n=x+y+z;
    vector<ll> a(n),b(n),c(n);
    for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];

    vector<pair<ll,int>> vec(n);
    for(int i=0;i<n;i++){
        vec[i]=make_pair(a[i]-b[i],i);
    }
    sort(vec.begin(),vec.end(),greater<>());
    priority_queue<ll,vector<ll>,greater<>> queA;
    ll sum=0;
    for(int i=0;i<x;i++){
        int idx=vec[i].second;
        queA.push(a[idx]-c[idx]);
        sum+=a[idx]-c[idx];
    }
    vector<ll> adp(n,-1e15);
    for(int i=x;i<n;i++){
        adp[i]=sum;
        int idx=vec[i].second;
        sum+=a[idx]-c[idx];
        queA.push(a[idx]-c[idx]);
        sum-=queA.top(); queA.pop();
    }
    priority_queue<ll,vector<ll>,greater<>> queB;
    sum=0;
    for(int i=n-1;i>=n-y;i--){
        int idx=vec[i].second;
        queB.push(b[idx]-c[idx]);
        sum+=b[idx]-c[idx];
    }
    vector<ll> bdp(n,-1e15);
    for(int i=n-y-1;i>=0;i--){
        bdp[i+1]=sum;
        int idx=vec[i].second;
        sum+=b[idx]-c[idx];
        queB.push(b[idx]-c[idx]);
        sum-=queB.top(); queB.pop();
    }
    ll res=-1e15;
    for(int i=0;i<n;i++){
        res=max(adp[i]+bdp[i],res);
    }

    res+=accumulate(c.begin(),c.end(),0LL);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 7432
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# print(factorization(0))
n = int(input())
if n == 1:
    print(0)
    exit()
n_fact = factorization(n)
ans = 0
# print(n_fact)

for i in n_fact:
    j = 1
    while i[1] >= j:
        ans += 1
        i[1] -= j
        j += 1

print(ans)


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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)

int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]

vi vis(100001,0);
vi adj[100001];

int main()
{	
    std::ios::sync_with_stdio(false);
    //srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
    ll r,d,x;
    cin>>r>>d>>x;
    for(int i=1; i<=10; ++i)
    {
    	cout<<(r*x)-d<<"\n";
    	x=(r*x)-d;
    }


}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int N, K;

signed main() {
   cin >> N >> K;
   vec<int> v(N);
   rep (i, N) {
      cin >> v[i];
   }
   sort(all(v));

   int ans = 1e10;
   repp (i, K-1, N) {
      // dbg2(i-K-1, i)
      ans = min(ans, abs(v[i] - v[i-K+1]));
   }

   cout << ans << endl;

   return 0;
}


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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;
use std::collections::VecDeque;

fn main() {
    input!{
      n: usize,
      m: usize,
      abs: [(usize, usize); n-1+m],
    }
    let mut edges = vec![vec![]; n];
    let mut rev_edges = vec![vec![]; n];
    let mut h = vec![0; n];
    for i in 0..abs.len() {
        let (a, b) = abs[i];
        edges[a-1].push(b-1);
        rev_edges[b-1].push(a-1);
        h[b-1] += 1;
    }
    // debug!(edges);

    let mut st = VecDeque::new();
    for i in 0..edges.len() {
        if h[i] == 0 {
            st.push_back(i);
        }
    }
    // debug!(h);

    let mut ans: Vec<i64> = vec![-1; n];
    while let Some(i) = st.pop_front() {
        for &t in edges[i].iter() {
            h[t] -= 1;
            if h[t] == 0 {
                st.push_back(t);
                ans[t] = i as i64;
            }
        }
    }
    for i in 0..n {
        println!("{}", ans[i] + 1);
    }
}


Measured memory_bytes: 21244
#include <cstdio>
#include <cmath>
#include <cstring>
#include <map>
#include <algorithm>
#define N 200005
using namespace std; 
inline char get(){
	const int TOP=1000000;
	static char T[TOP],*x=T,*y=T;
	return x==y&&(y=(x=T)+fread(T,1,TOP,stdin),x==y)?EOF:*x++;
}
inline int read (){
	register int num;int sign=1;register char c;
	while (((c=get())<'0'||c>'9')&&c!='-');c=='-'?num=sign=0:num=c-48;
	while ((c=get())>='0'&&c<='9')num=(num<<3)+(num<<1)+(c-48);
	return sign?num:-num;
}
int n,h,w,ans,x,y;
int main(){
	n=read();h=read();w=read();
	for(int i=1;i<=n;++i){
		x=read();y=read();
		if(x>=h&&y>=w)ans++;
	}
	printf("%d\n",ans);
} 

Measured memory_bytes: 128
#include<iostream>
using namespace std;
 
int main(){
 
int a,b;
 
cin >> a>>b;
 
if(a>b) cout<<"a > b"<<endl;
else if(a<b) cout<<"a < b"<<endl;
else cout<<"a == b"<<endl;
 
 
return 0;
 
}

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

int main(){
	
	int n;
	
	cin >> n;
	
	int ans = 0;
	
	for (int i = 1; i <= n; i++){
		string s = to_string(i);
		if (s.length() % 2 != 0){
			ans++;
		}
	}
	
	cout << ans;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int a,b;
    cin >> a >> b;
    if(a+b >= 10){
        cout << "error\n";
    }else{
        cout << a+b << endl;
    }
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    private static int MIN = -1000;
    private static int MAX = 1000;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int[] a_b = Stream.of(sc.nextLine().split(" "))
                    .mapToInt(Integer::parseInt)
                    .toArray();
            if (a_b.length != 2
                    || a_b[0] > MAX || a_b[0] < MIN
                    || a_b[1] > MAX || a_b[1] < MIN) {
                System.out.println("Condition is invalid.");
                return;
            }
            int a = a_b[0];
            int b = a_b[1];
            if (a == b) {
                System.out.println("a == b");
            } else if (a > b) {
                System.out.println("a > b");
            } else {
                System.out.println("a < b");
            }
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }
}



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

typedef long int lint;
typedef long long int llint;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n";

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string str;
  bool ct[4];

  cin >> str;
  REP(i, 4) ct[i] = false;
  REP(i, str.size()){
    if (str[i] == 'N')  ct[0] = true;
    if (str[i] == 'W')  ct[1] = true;
    if (str[i] == 'S')  ct[2] = true;
    if (str[i] == 'E')  ct[3] = true;
  }

  if (ct[0] == ct[2] && ct[1] == ct[3]){
    cout << "Yes";
  }
  /*
  if ((ct[0] && ct[2]) || ct[0] == ct[2]){
    cout << "Yes";
  }
  else if ((ct[1] && ct[3] || ct[1] == ct[3])){
    cout << "Yes";
  }*/
  else {
    cout << "No";
  }
  cout << endl;
  
}



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

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){
    if(a>b) {
        a = b;
        return true;
    }
    return false;

}
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

/*
 *
 * */

int main() {

    int A,B,C,D;
    cin >> A >> B >> C >> D;


    string ans;
    bool isTakahasi = true;
    while(true){

        if(isTakahasi){
            C -= B;

            if(C <= 0){
                ans = "Yes";
                break;
            }
            isTakahasi =false;
        }else{

            A -= D;
            if(A <= 0){
                ans = "No";
                break;
            }
            isTakahasi = true;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
function main(i) {
  i = i.split('\n');
  var a = Number(i[0]), b = Number(i[1]), c = Number(i[2]), d = Number(i[3]), e = Number(i[4]), k = Number(i[5]);
  if (k >= e - a) {
    console.log('Yay!');
  } else {
    console.log(':(');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N;ll x;cin>>N>>x;
    ll a[100010];
    for(int i=0;i<N;i++)
        cin>>a[i];
    ll ans=0;
    for(int i=0;i<N-1;i++){
        ll s=a[i]+a[i+1];
        if(s>x){
            ans+=s-x;
            if(a[i+1]>=s-x){
                a[i+1]-=s-x;
            }
            else a[i+1]=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>


int main(){
    char str[200];
    char cpy[200];
  
    
    
    while(1)
    {
          int m,i,j,mc=0;
        scanf("%s%d",str,&m);
        if(strcmp(str,"-")==0)
            break;
        
        while(mc<m){
            int h; scanf("%d",&h);
            for(i=0;i<h;i++)
               cpy[i]=str[i];
            for(j=0;j<strlen(str)-h;j++)
               str[j]=str[h+j];
            for(i=0;i<h;i++)
               str[strlen(str)-h+i]=cpy[i];
            mc++;
        }
        
    printf("%s\n",str);
        
    }
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 2140
#include<stdio.h>
int main(){
  int n,m,i,sum=0;
  scanf("%d",&n);
  int t[n+1];
  for(i=0;i<n;i++){
    scanf("%d",&t[i]);
    sum+=t[i];
  }
  scanf("%d",&m);
  int p[m+1][2];
  for(i=0;i<m;i++)
    scanf("%d%d",&p[i][0],&p[i][1]);
  for(i=0;i<m;i++)
    printf("%d\n",sum-t[p[i][0]-1]+p[i][1]);
  return 0;
}

Measured memory_bytes: 1724
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

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

			int n = sc.nextInt();

			int[] pArray = new int[n];
			int[] qArray = new int[n];

			for(int i = 0 ; i < n ; i++ ) {
				pArray[i] = sc.nextInt();
			}

			for(int i = 0 ; i < n ; i++ ) {
				qArray[i] = sc.nextInt();
			}

			//先頭が違う場合 p2..pn < seq(p2,pn)となるseqの数
			//p1 < r < q1となるseqの数
			//(q2, qn) < seq(q2, qn)となるseqの数
			//上記は最初に違う数がきた箇所に対して適用可能
			// --> 以下は違う解き方

			List<Integer> seq = new ArrayList<>();
			for(int i = 0 ; i < n ; i++ ) {
				seq.add(i+1);
			}

			List<List<Integer>> comb = make(seq);

			//			for(List<Integer> lst : comb) {
			//				for(int i : lst ) {
			//					System.out.print(i);
			//				}
			//				System.out.println();
			//			}

			int pNum = -1;
			int qNum = -1;

			for(int i = 0 ; i < comb.size() ; i++ ) {
				List<Integer> aSeq = comb.get(i);

				if ( pNum == - 1 ) {
					boolean pMatch = true;
					for(int j = 0 ; j < n ; j++ ) {
						if (pArray[j] != aSeq.get(j) ) {
							pMatch = false;
							break;
						}
					}
					if ( pMatch ) {
						pNum = i;
					}
				}
				if ( qNum == -1 ) {
					boolean qMatch = true;
					for(int j = 0 ; j < n ; j++ ) {
						if (qArray[j] != aSeq.get(j) ) {
							qMatch = false;
							break;
						}
					}
					if ( qMatch ) {
						qNum = i;
					}
				}
			}
			
			System.out.println(Math.abs(pNum - qNum));
		}
	}

	public static List<List<Integer>> make(List<Integer> candidate) {
		// 候補がないなら、順列は空リストを返す
		if (candidate.size() == 0) {
			List<List<Integer>> empty = new ArrayList<>();
			empty.add(new ArrayList<>());
			return empty;
		}

		// candidateから1文字ずつピックアップする
		// flatMapを使ってるので1文字はiに格納されるはず
		return candidate.stream().flatMap(i -> {
			// 残りの配列はcandidateからiを省いたものである
			List<Integer> rest = new ArrayList<>(candidate);
			rest.remove(i);
			// 残りの配列で順列のリストを作り、
			// 先頭にピックアップした文字を結合
			return make(rest).stream().map(list -> {
				list.add(0, i);
				return list;
			});
		}).collect(Collectors.toList());
		// flatMapを使っているので、1文字ずつピックアップして
		// 全文字の操作が終わったら、全ての操作で得られたリストを
		// 結合して返しているはず
	}
}

Measured memory_bytes: 69048
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = ns()
s = list(s)
asc = range(97,123)

import bisect

if len(s) < 26:
    ss = [ord(u) for u in s]
    for i in asc:
        if i not in ss:
            s.append(chr(i))
            print(''.join(s))
            exit()
else:
    ss = s[::-1]
    a = [ord(ss[0])]
    for i in range(1,len(ss)):
        j = ord(ss[i])
        if j > a[-1]:
            a.append(j)
        else:
            k = bisect.bisect_right(a,j)
            x = chr(a[k])
            sss = s[:26-(i+1)] + [x]
            print(''.join(sss))
            exit()
    print(-1)


Measured memory_bytes: 3188
#include<cstdio>
const int N=1e5+3;
int n,m,deg[N];
signed main(){
	int u,v;
	scanf("%d%d",&n,&m);
	for(;m--;)
	  scanf("%d%d",&u,&v),deg[u]++,deg[v]++;
	for(u=1;u<=n;u++)if(deg[u]&1)return 0*puts("NO");
	return 0*puts("YES");
}

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

using namespace std;

#define Fast  ios::sync_with_stdio(false); cin.tie(0)
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define S second
#define F first
typedef long long ll;
const int mod = 1e9 + 7;
const ll N = 1e6 + 5;
ll inf = 1e18;

ll dp[N];

int main(){

    Fast;

    ll n;
    cin >> n;

    dp[3] = 1;
    for(int i = 4; i <= n; i ++){
         dp[i] = 1;
        for(int j = 1; j <= i-3; j ++){
            dp[i] += dp[j];
            dp[i] %= mod;
        }
    }
    cout << dp[n];

    return 0;
}


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

int main(){
    string S;
    cin >> S;
    bool end = true;

    string x, y;
    if(S.length() % 2 == 1) S.pop_back();
    else {
        S.pop_back();
        S.pop_back();
    }

    while(end){
        for(int i=0, j=S.length()/2; i<S.length()/2; i++, j++){
            if(S[i] != S[j]) {
                S.pop_back();
                S.pop_back();
                break;
            }
            if(i == S.length()/2-1){
                end = false;
            }
        }
    }

    cout << S.length() << endl;
}


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

using namespace std;

int main(void){
  string a,b,c;
  cin >> a >> b >> c;
  a[0]=a[0]-32;b[0]=b[0]-32,c[0]=c[0]-32;
  cout << a[0] << b[0] << c[0] << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
li=[[] for i in range(n+1)]

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

for i in range(1,n+1):
    print(len(li[i]))
    

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a.at(i);

	int ans = 0;
	bool can = true;
	while(can){
		rep(i, n){
			if(a.at(i)%2 != 0)
				can = false;
		}
		if(!can) break;
		rep(i, n) a.at(i) /= 2;
		ans++;
	}

	cout << ans << endl;
}

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

bool is_number( const string& s, int a, int b ) {
	for( int i = a; i < b; ++i ) {
		if( s[i] < '0' || s[i] > '9' ) {
			return false;
		}
	}

	return true;
}

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

	int A, B;
	string S;
	cin >> A >> B >> S;

	bool result = is_number( S, 0, A )
		&& S[A] == '-'
		&& is_number( S, A+1, A+1+B );

	cout << (result ? "Yes" : "No") << endl;
	return 0;
}


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

char m[8][9];

void disp(){
  for(int i=0; i<8; i++)
    cout << m[i] << endl;
}

void rot(){
  for(int i=0; i<4; i++)
    for(int j=0; j<4; j++){
      char c = m[i][j];
      m[i][j] = m[7-j][i];
      m[7-j][i] = m[7-i][7-j];
      m[7-i][7-j] = m[j][7-i];
      m[j][7-i] = c;
    }
}

int main(void){
  for(int i=0; i<8; i++)
    cin >> m[i];
  //disp();
  rot();
  cout << 90 << endl;
  disp();
  rot();
  cout << 180 << endl;
  disp();
  rot();
  cout << 270 << endl;
  disp();
  return 0;
}

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

long long n,res=0;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n;

    if(n%2)
    {
        cout<<0;
        return 0;
    }
    n/=2;
    for(long long i=5;i<=n;i*=5)
    res+=n/i;
    cout<<res;
}


Measured memory_bytes: 256
x=int(input())
z=[111,222,333,444,555,666,777,888,999]
for i in range(9):
  if x==z[i]:
    print(z[i])
    break
  elif i==0 and x<z[i]:
    print(z[i])
    break
  elif i!=8 and z[i]<x<z[i+1]:
    print(z[i+1])
    break
  elif i==8 and x<z[i]:
    print(z[i])
    break

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


int main(){
	int N, A, B;
	cin >> N >> A >> B;
	int ans = 0;;
	rep(i,N+1){
		int tmp = i;
		int res = 0;
		while(tmp){
			res += tmp%10;
			tmp /= 10;
		}
		if(A <= res && res <= B){
		   	ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}
			

		












Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
void sink(vector<vector<int>> &v, int x, int y, int size) {
	v[x][y]++;
	if (x + 1 < 10)v[x + 1][y]++;
	if (0 <= x - 1)v[x - 1][y]++;
	if (y + 1 < 10)v[x][y + 1]++;
	if (0 <= y - 1)v[x][y - 1]++;

	if (size >= 2) {
		if (x + 1 < 10) {
			if (y + 1 < 10)v[x + 1][y + 1]++;
			if (y - 1 >= 0)v[x + 1][y - 1]++;
		}
		if (x - 1 >= 0) {
			if (y + 1 < 10)v[x - 1][y + 1]++;
			if (y - 1 >= 0)v[x - 1][y - 1]++;
		}
	}

	if (size >= 3) {
		if (x + 2 < 10)v[x + 2][y]++;
		if (x - 2 >= 0)v[x - 2][y]++;
		if (y + 2 < 10)v[x][y + 2]++;
		if (y - 2 >= 0)v[x][y - 2]++;
	}
}
signed main() {
	char c; int x, y, s;
	vector<vector<int>>v(10, vector<int>(10, 0));
	while (cin >> x >> c >> y >> c >> s) {
		sink(v, x, y, s);
	}
	int cnt(0);
	int m(0);
	rep(i, 0, 10) {
		rep(j, 0, 10) {
			m = max(m, v[i][j]);
			if (v[i][j] == 0)cnt++;
		}
	}
	cout << cnt << endl << m << endl;
	return 0;
}

Measured memory_bytes: 3152
#include<iostream>
#include<cstdio>
using namespace std;
long long Pow(long long a,long long p){
    long long re=1;
    for(;p;p>>=1){
        if(p&1) re=re*a;
        a=a*a;
    }
    return re;
}
int main(){
    long long n,p;
    cin>>n>>p;
    long long g=1;
    for(long long i=2;i*i<=p;i++){
        if(p%i==0){
            long long cnt=0;
            while(p%i==0){
                p/=i;cnt++;
            }
            g*=Pow(i,cnt/n);
        }
    }
    if(p>1) g*=Pow(p,1/n);
    cout<<g;
}


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

#define N 1000000
#define L 12

  char A[N][L];
  int getChar(char c);
  long long getKey(char str[]);
  int g1(int key){
    return key%N;
  }

  int g2(int key){return 1+(key%(N-1));}
  int find(char str[]);
  int insert(char str[]);

  int main(){
    int i,n;
    char str[L],cmp[9];
    for(i=0;i<N;i++){
      A[i][0]='\0';
    }
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%s %s",cmp,str);
      if(cmp[0]=='i'){
        insert(str);
      } else {
        if(find(str)){
          printf("yes\n");
        } else {
          printf("no\n");
        }
      }
    }
    return 0;
  }
  int getChar(char c){
    if(c=='A')return 1;
    else if(c=='C')return 2;
    else if(c=='G')return 3;
    else if(c=='T')return 4;
    else return 0;
}
  long long getKey(char str[]){
    long long sum=0,p=1,i;
    for (i=0;i<strlen(str);i++){
      sum+=p*(getChar(str[i]));
      p*=5;
    }
    return sum;
  }
  int find(char str[]){
    int i,x;
    x=(g1(getKey(str))+i*g2(getKey(str)))% N;
    for(i=0;i<14;i++){
      x=(g1(getKey(str))+i*g2(getKey(str)))%N;
        if(strcmp(A[x],str) == 0) return 1;
      }
      return 0;
    }
    int insert(char str[]){
      int i;
      if(find(str))return 0;
      for(i=0;i<14;i++){
          if(A[(g1(getKey(str))+i*g2(getKey(str)))%N][0]=='\0'){
            strcpy(A[(g1(getKey(str))+i*g2(getKey(str)))%N],str);
            return 1;
          }
        }
  return 0;
  }



Measured memory_bytes: 13452
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

ll AN(ll A, ll N){
  if (N == 0) return 1;
  else{
    if (N % 2 == 0){
      return AN(A * A % nmax, N / 2) % nmax;
    }else{
      return (A * AN(A * A % nmax, N / 2)) % nmax;
    }
  }
}
int main(){
  int N; cin >> N;
  vector <ll> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  ll ans = 0;
  for (int i = 0; i < 63; i++){
    ll cnt = 0;
    for (int j = 0; j < N; j++){
      if (A[j] % 2 == 0) cnt++;
      A[j] /= 2;
    }
    ll now = cnt * (N - cnt); now %= nmax;
    ans += AN(2, i) * now;
    ans %= nmax;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
#define pi 3.1415926

int a[(int)2e5][11];

int main(){
    int n;
    cin >> n;
    int x, br=0;
    while(n > 0){
        x = n%10;
        if(x  == 7)
            br++;
        n = n/10;
    }
    if(br > 0)
        cout << "Yes";
    else 
        cout << "No";
}

    

		


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll x;
    cin >> x;

    double d = sqrt(sqrt(x));
    ll a = d;

    for (ll i = -d - 1; i <= d; i++)
    {
        for (ll j = -d - 1; j <= d; j++)
        {
            if (i * i * i * i * i - j * j * j * j * j == x)
            {
                cout << i << " " << j << endl;
                exit(0);
            }
        }
    }
}

Measured memory_bytes: 3580
#include<iostream>
#include<cstring>
#include<algorithm>
#define INF 1<<28
using namespace std;
 
int p[222];
int memo[1111111];
int memo2[1111111];
 
int solve(int n){
   
  if(!n) return 0;
  if(~memo[n]) return memo[n];
 
  int ans = INF;
  for(int i=180;i>0;i--) if(n >= p[i]) ans = min(ans, solve(n-p[i])+1);
   
  return memo[n] = ans;
}
 
int solve2(int n){
   
  if(!n) return 0;
  if(~memo2[n]) return memo2[n];
 
  int ans = INF;
  for(int i=180;i>0;i--) if(p[i]&1 && n >= p[i]) ans = min(ans, solve2(n-p[i])+1);
 
  return memo2[n] = ans;
}
 
int main(){
   
  int n;
   
  memset(memo, -1, sizeof(memo));
  memset(memo2, -1, sizeof(memo2));
 
  for(int i=0;i<181;i++) p[i] = i*(i+1)*(i+2)/6;

  for(int i=0;i<1111111;i+=10){ solve(i), solve2(i); }
  while(cin >> n, n) cout << solve(n) << " " << solve2(n) << endl;
 
}

Measured memory_bytes: 9848
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+5;
typedef long long ll;
char s[maxn];
int n;
int a[maxn];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	int tmp=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='<') tmp++;
		else tmp=0;
		a[i+1]=tmp;
	}
	tmp=0;
	for(int i=n;i>=1;i--){
		if(s[i]=='>') tmp++;
		else tmp=0;
		a[i]=max(a[i],tmp);
	}
	ll ans=0;
	for(int i=1;i<=n+1;i++) ans+=a[i];
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 2688
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  string str;
  cin>>str;
  int flag=0;
  for(int i=0;i<str.size()-1;i++){
    if(str[i]=='A'&&str[i+1]=='C'){
      flag=1;
      break;
    }
  }
  if(flag)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
// Sum of gcd of Tuples (Easy)
func gcd(_ a:Int, _ b:Int) -> Int {
  if a == b {
    return a
  }
  return gcd(min(a, b), abs(b-a))
}


func main() {
  let n = Int(readLine()!)!
  var sum = 0
  for a in 1...n {
    for b in 1...n {
      for c in 1...n {
        sum += gcd(gcd(a,b), c)
      }
    }
  }
  print(sum)
}

main()

Measured memory_bytes: 7720
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,total,l,r;
    cin>>n;
    total=0;
    for(i=1;i<=n;i++)
    {
        cin>>l>>r;
        total=(abs(l-r))+1+total;
    }
    cout<<total<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#define input std::cin

using lint = long long int;
using vector = std::vector<lint>;
using string = std::string;

int main() {
  lint n, x, m; input >> n >> x >> m;
  vector sums; sums.reserve(m); sums.push_back(0);
  std::unordered_map<int, lint> seen;
  lint running = 0;
  for (int i=0; i<n; i++) {
	if (seen.count(x)) {
	  int prev = seen[x];
	  int period = (i+1)-prev;
	  n -= prev-1;
	  lint ans = sums[prev-1] + (running-sums[prev-1]) * (n/period) + (sums[prev-1+n%period]-sums[prev-1]);
	  running = ans;
	  break;
	}
	else {
	  running = (running + x);
	  seen.insert({x,i+1});
	  x = (x*x) % m;
	  sums.push_back(running);
	}
  }
  std::cout << running << std::endl;
}



Measured memory_bytes: 5392
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if(a * b * c == 5*5*7){
      System.out.println("YES");
    } else {    	
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 23380
#include <cstdio>
#include <set>
#include <algorithm>

int main() {
  std::set<int> sq;
  for (int i=1; i*i<=(1<<15); ++i) sq.insert(i*i);

  auto end = sq.end();

  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 0) break;

    int res = sq.count(n);
    for (auto i=sq.begin(); i!=end; ++i)
      for (auto j=i; j!=end; ++j)
        for (auto k=j; k!=end; ++k) {
          int x = n-*i-*j-*k;
          if (*k <= x && sq.count(x)) {
            ++res;
          }
        }

    for (auto i=sq.begin(); i!=end; ++i)
      for (auto j=i; j!=end; ++j) {
        int x = n-*i-*j;
        if (*j <= x && sq.count(x)) {
          ++res;
        }
      }

    for (auto i=sq.begin(); i!=end; ++i) {
      int x = n-*i;
      if (*i <= x && sq.count(x)) {
        ++res;
      }
    }

    printf("%d\n", res);
  }
}



Measured memory_bytes: 2692
#include <stdio.h>

int main(void)
{
	int W,H,i,j;
	
	
	scanf("%d %d",&H,&W);
	while(H != 0 && W != 0)
	{
		for(i=0;i<H;i++)
		{
			for(j=0;j<W;j++)
			{
				if(i==0 || i==H-1)
					printf("#");
				else
				{
					if(j==0 || j==W-1)
						printf("#");
					else
						printf(".");
				}
				
			}
			printf("\n");
		}
		scanf("%d %d",&H,&W);
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 572
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main()
{
  int n, ans=0;
  cin >> n;
  vector<int> A(n);
 
  for(int i=0; i<n; i++){
    cin >> A[i];
  }
  
  sort(A.begin(), A.end(), greater<int>());
   
  for (int i=0; i<n; i++){
    if(i%2==0){
      ans += A[i];
    }
    else{
      ans -= A[i];
    }
  }
  cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<n; ++i)
using ll = long long;

const ll Inf = (1U << 62) -1;
int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];

    vector<ll> dp(n + k + 100, Inf);
    dp[0] = 0;

    for (ll i=0; i<n; ++i) {
        for (ll j=1; j <= k; ++j) {
            ll c = dp[i]+abs(h[i+j]-h[i]);
            dp[i+j] = min(dp[i+j], c);
        }
    }

    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 4472
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    int i;
    int x,m;
    char s[105];
    while(scanf("%d",&n) != EOF)
    {
        x = 0;
        m = 0;
        scanf("%s",s);
        for(i = 0;s[i] != '\0';i++)
        {
            if(s[i] == 'I') x += 1;
            else x -= 1;
            if(x > m) m = x;
        }
        printf("%d\n",m);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
constexpr int MOD = 998244353;
int n, s, a;
long long dp[3005], ans;
int main(){
	scanf("%d%d", &n, &s);
	rep(i,n){
		scanf("%d", &a);
		for(int j=s; j>a; j--) (dp[j] += dp[j-a]) %= MOD;
		dp[a] += i+1;
		(ans += dp[s]) %= MOD;
	}
	printf("%lld\n", ans);
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

bool input(){
  char c;
  cin >> c;
  return c == 'Y';
}

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

  int d = -1;
  string s = "1";
  for(int i=0;i<=10;++i){
	cout << "? " << s << endl;
	if(!input()){
	  d = i;
	  break;
	}
	s += "0";
  }
  if(d < 0){
	s = "9";
	for(int i=1;i<=10;++i){
	  cout << "? " << s << endl;
	  if(input()){
		d = i;
		break;
	  }
	  s += "9";
	}
  }
  if(d == 10){
	cout << "! 1000000000" << endl;
	return 0;
  }

  string ans;
  for(int i=0;i<d-1;++i){
	int lb = 0, ub = 10;
	while(ub-lb > 1){
	  int m = (lb + ub) / 2;
	  string q = ans + string(1, '0'+m);
	  cout << "? " << q << endl;
	  if(input()){
		lb = m;
	  }
	  else{
		ub = m;
	  }
	}
	ans += string(1, '0'+lb);
  }
  {
	int lb = -1, ub = 9;
	while(ub-lb > 1){
	  int m = (lb + ub) / 2;
	  string q = ans + string(1, '0'+m);
	  cout << "? " << q + "0" << endl;
	  if(!input()){
		lb = m;
	  }
	  else{
		ub = m;
	  }
	  if(d == 1 && ub == 1) break;
	}
	ans += string(1, '0'+ub);
  }
  cout << "! " << ans << endl;

  return 0;
}


Measured memory_bytes: 628
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < (int)(x); i++)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<ld, ld> Pld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int n; cin >> n;
    vector<Pld> vec(n);
    rep(i,n){
        ld x,y;cin >> x >> y;
        vec[i] = Pld(x,y);
    }
    sort(all(vec));
    ld sum = 0;
    do{
        ld temp = 0;
        rep(i,n-1){
            ld x = vec[i+1].first - vec[i].first;
            ld y = vec[i+1].second - vec[i].second;
            temp += sqrt(x * x + y * y);
        }
        sum += temp;
    }while(next_permutation(all(vec)));

    ld ma = 1;
    for(int i = 1; i < n+1;++i)ma *= i;
    cout << fixed << setprecision(10) << sum / ma << endl;

}

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

const int N = 205;
const int INF = (int) 1e9;

int a, b, c;
int n, m, r;
int vis[N];
vector<pair<int,int> > g[N]; 
vector<int> dist[N];

void build(int s, vector<int> &get) {
	priority_queue< pair<int,int> , vector< pair<int,int> >, greater< pair<int,int> > > pq;
	pq.push(make_pair(get[s] = 0, s));

	while(! pq.empty()) {
		int u = pq.top().second, d = pq.top().first; pq.pop();
		if(d > get[u])
			continue;

		for(auto now : g[u]) {
			int v = now.first, w = now.second;
			if(get[u] + w < get[v]) {
				get[v] = get[u] + w;
				pq.push(make_pair(get[v], v));
			}
		}
	}
}

int main() {
	scanf("%d %d %d", &n, &m, &r);
	for(int i = 0; i < r; ++i) {
		scanf("%d", &vis[i]);
	}
	for(int i = 0; i < m; ++i) {
		scanf("%d %d %d", &a, &b, &c);
		g[a].push_back(make_pair(b, c));
		g[b].push_back(make_pair(a, c));
	}

	for(int i = 0; i < r; ++i) {
		dist[vis[i]].assign(n + 1, INF);
		build(vis[i], dist[vis[i]]);
	} 

	int ans = INT_MAX;

	sort(vis, vis + r);
	do {
		int cost = 0;
		for(int i = 0; i < r - 1; ++i) {
			cost += dist[vis[i]][vis[i + 1]];
		}
		// fprintf(stderr, "%d\n", cost);
		ans = min(ans, cost);
	} while(next_permutation(vis, vis + r));
	printf("%d\n", ans);
}

Measured memory_bytes: 768
#include<iostream>

using namespace std;

int main() {
	int N, D, X;
	cin >> N >> D >> X;
	int ans = X;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		ans += (D - 1) / A + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
mod = int(1e9 + 7)
N = int(input())
A = [format(i, '060b') for i in map(int, input().split())]
S = 0
for k in range(60):
  s = [b[59-k] for b in A]
  v = s.count('0')*s.count('1')
  S += (v<<k)
S %= mod
print(S)


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

#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
#define rep(i,a,n) for(int i=a; i<n; i++)
#define endl "\n"
#define E "\n"
#define show(arr) REP(i,arr.size()){cout<<arr[i]<<" ";}
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
const int MAX = 1e18;

#define N 5010

void solve()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int x = (k%2==1)?-1:1;
    if (a<INF&&b<INF&&c<INF){
        cout<<x*(a-b);
    }
    else{
        cout<<"Unfair";
    }
}

signed main()
{
    int t=1;
    //cin>>t;
    WL(t)solve();

    return 0;
}




Measured memory_bytes: 3588
"""
fast way to compute a combination using inverse factorials
O(N) to construct tables -> O(1) to compute each combination
"""


def get_fact_and_inv(limit: int, MOD: int) -> tuple:
    """Compute mod tables of factorials and inverse factorials (1-indexed)."""
    factorials = [0] * (limit + 1)
    factorials[0] = 1
    x = 1
    for i in range(1, limit + 1):
        x = (x * i) % MOD
        factorials[i] = x

    inverse_factorials = [1] * (limit + 1)
    inverse_factorials[-1] = pow(factorials[-1], MOD - 2, MOD)
    x = inverse_factorials[-1]
    for i in range(limit - 1, 0, -1):
        x = (x * (i + 1)) % MOD
        inverse_factorials[i] = x
    return factorials, inverse_factorials


def mod_comb(n: int, r: int, MOD: int) -> int:
    """Compute nCr % MOD using a mod table of inverse factorials."""
    return fact[n] * inv[r] * inv[n - r] % MOD


# e.g. ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D)
def main():
    global fact, inv
    H, W, A, B = map(int, input().split())
    MOD = 10 ** 9 + 7
    fact, inv = get_fact_and_inv(H + W, MOD)
    x, y, a = H - A - 1, W + A - 2, A - 1  # fixed variables
    f = lambda i: mod_comb(x + i, i, MOD) * mod_comb(y - i, a, MOD)
    ans = sum(f(i) for i in range(B, W)) % MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18804
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

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

enum { kN = 20002 };

int N, S, R[kN];

int main() {
  while (-1 != scanf("%d%d", &N, &S)) {
    if (!(N)) break;
    rep(i,N) scanf("%d", R+i);    
    sort(R, R+N);
    int ans = 0;
    rep(i,N-1) {
      int t = (R+N) - lower_bound(R+i+1, R+N, S-R[i]+1);
      // ans += t < N ? t : 0;
      ans += t;
    }
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 916
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = [0] * N
    for n in range(N):
        A[n] = int(input())
    
    A.sort()
    ans1 = sum([-2*a for a in A[:N//2+N%2]]) + sum([2*a for a in A[N//2+N%2:]])
    if N % 2:
        ans1 += A[N//2-1]
        ans1 += A[N//2]
    else:
        ans1 += A[N//2-1]
        ans1 -= A[N//2]

    ans2 = sum([-2*a for a in A[:N//2]]) + sum([2*a for a in A[N//2:]])
    if N % 2:
        ans2 -= A[N//2]
        ans2 -= A[N//2+1]
    else:
        ans2 -= A[N//2]
        ans2 += A[N//2-1]

    print(max(ans1, ans2))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9640
object Main extends App {
  val n: Int = io.StdIn.readLine().toInt
  val arr: Array[Int] = io.StdIn.readLine().split(" ") map(_.toInt)

  def partition(a: Array[Int], pv: Int, r:Int): Int = {
    var p: Int = pv

    for(i <- p until r) {
      val (ai, ap, ar) = (a(i), a(p), a(r))
      if (i == p) {if (ai <= ar) p += 1}
      else {if (ai <= ar && ai < ap) {a(i) = ap; a(p) = ai; p += 1}}
    }
    val ap = a(p)
    a(p) = a(r); a(r) = ap
    p
  }

  val p: Int = partition(arr, 0, n-1)
  println(arr.slice(0, p).mkString(" ") + " [" + arr(p) + "] " + arr.slice(p+1, n).mkString(" "))
}

Measured memory_bytes: 85372