akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[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" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{n:usize, k:i64, a:[i64;n]};
    let mut n = n as i64 - k;
    let mut ans = 1;

    while n > 0 {
        n -= k-1;
        ans += 1;
    }
    println!("{}", ans);
}

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

int digitssum(int n){
  int ans=0;
  while(n != 0){
    ans+=n%10;
    n/=10;
  }
  return ans;
}

int main(){
  int N;
  cin>>N;
  int minans=1000000000;
  for(int i=1;i<=N-1;i++){
    int temp=0;
    temp=digitssum(i)+digitssum(N-i);
     minans=min(minans,temp);
  }
  cout<<minans<<endl;
  return 0;
}
    
    
  

Measured memory_bytes: 3556
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    ll s;
    cin>>s;
    set<ll> v;
    v.insert(s);
    int ans;
    while (1)
    {
        if (s&1)
            s=3*s+1;
        else
            s/=2;
        if (v.find(s)!=v.end())
        {
            ans=v.size()+1;
            break;
        }
        v.insert(s);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#python3
n=int(input())
h=[int(i) for i in input().split()]

def solve():
  h[0]-=1
  for i in range(1,n):
    if h[i] > h[i-1]:
      h[i]-=1
    elif h[i] == h[i-1]:
      pass
    else :
      print('No')
      return 0
  return 1
    

if solve():
  print('Yes')


Measured memory_bytes: 14396
#include <iostream>
using namespace std;
int main(){
  string s;
  cin >>s;
  if(s[0]==s[1]&&s[1]==s[2]){
    cout <<"Yes"<<endl;
    }
    else{
      if(s[1]==s[2]&&s[2]==s[3]){
        cout<<"Yes"<<endl;
        }
      else{
  cout << "No" <<endl;
      }
      }
  return 0;
  }

    

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define ld long double
#define MAX 100007
#define pb push_back
#define MOD 1000000007
using namespace std;

int main()
{
    ll a,b,t;
    cin>>a>>b>>t;
    cout<<b*(t/a);
    return 0;
}

Measured memory_bytes: 256
N = int(input())

ans = -1
tmp = -1 #直前の数字
for i in range(N):
    A = int(input())
    if A > i:
        print (-1)
        exit()
    if tmp + 1 < A:
        print (-1)
        exit()
    if tmp + 1 == A:
        ans += 1
        tmp += 1
    else:
        ans += A
        tmp = A

print (ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;
  string s;
  cin >> n >> s;
  cout << (count(all(s), 'R') > count(all(s), 'B') ? "Yes" : "No") << newl;
  return 0;
}

Measured memory_bytes: 3580
a = input()
b = input()
c = input()
win = 'a'
while len(a)>=0 and len(b)>=0 and len(c)>=0:
    if win == 'a':
        if len(a)==0:
            break
        win = a[0]
        a = a[1:]
    elif win == 'b':
        if len(b)==0:
            break
        win = b[0]
        b = b[1:]
    else:
        if len(c)==0:
            break
        win = c[0]
        c = c[1:]
print('A' if win == 'a' else 'B' if win == 'b' else 'C')


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

inline bool in(int x, int y)
{
    return (0<=x&&x<=5000 && 0<=y&&y<=5000);
}

int main()
{
    int n;
    while(cin >>n,n)
    {
        set<pi> p;

        vector<pi> v(n);
        rep(i,n)
        {
            scanf(" %d %d", &v[i].fi, &v[i].se);
            p.insert(v[i]);
        }

        sort(all(v));

        int ans=0;

        //2???????????¶
        rep(i,n)rep(j,i)
        {
            int dx=v[i].fi-v[j].fi;
            int dy=v[i].se-v[j].se;

            int p1x=v[j].fi-dy,p1y=v[j].se+dx;
            int p2x=v[i].fi-dy,p2y=v[i].se+dx;
            if(in(p1x,p1y) && in(p2x,p2y))
            {
                if(p.find(pi(p1x,p1y))!=p.end() && p.find(pi(p2x,p2y))!=p.end()) ans=max(ans,dx*dx+dy*dy);
            }

            int q1x=v[j].fi+dy,q1y=v[j].se-dx;
            int q2x=v[i].fi+dy,q2y=v[i].se-dx;
            if(in(q1x,q1y) && in(q2x,q2y))
            {
                if(p.find(pi(q1x,q1y))!=p.end() && p.find(pi(q2x,q2y))!=p.end()) ans=max(ans,dx*dx+dy*dy);
            }
        }

        cout << ans << endl;
    }
    return 0;
}

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

int n;
char buf1[114514191];
char buf2[114514191];

int ConvertInt(string s) {
  int ret = 0;
  map<char, int> mcxi;

  mcxi['m'] = 1000;
  mcxi['c'] = 100;
  mcxi['x'] = 10;
  mcxi['i'] = 1;
  for (int i=0; i<s.size(); i++) {
    if (mcxi[s[i]]) {
      int m = 1;
      if (i-1 >= 0 && !mcxi[s[i-1]]) {
        m = s[i-1] - '0';
      }

      ret += m * mcxi[s[i]];
    }
  }

  return ret;
}

string MCXI(int t) {
  int cs[5];
  string ret;

  for (int i=0; i<4; i++) {
    cs[i] = t%10;
    t /= 10;
  }

  for (int i=3; i>=0; i--) {
    if (cs[i] == 0) continue;
    if (cs[i] != 1) ret += ('0'+cs[i]);
    ret += "ixcm"[i];
  }

  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf(" %s", buf1);
    scanf(" %s", buf2);
    int a = ConvertInt(buf1);
    int b = ConvertInt(buf2);
    printf("%s\n", MCXI(ConvertInt(buf1)+ConvertInt(buf2)).c_str());
  }
}

Measured memory_bytes: 3248
import java.util.Scanner;

//ほぼ写経
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		boolean[] flg = new boolean[N.length()-1];
		System.out.println(bits(flg,0,N));
	}
	//flagがtrueの場所には+を挿入する．どこを見ているかをindex,
	public static long bits(boolean[] flg,int index,String s) {
		if (flg.length == index) {
			return calSum(flg,s);
		} else {
			long sum = 0;
			flg[index] = true;
			sum += bits(flg, index+1, s);
			flg[index] = false;
			sum += bits(flg, index+1, s);
			return sum;
		}
	}

	public static long calSum(boolean[] flg, String s) {
		long sum = 0;
		int start = 0;
		for (int i = 0; i < flg.length; i++) {
			if (flg[i]) {
				sum += Long.parseLong(s.substring(start, i+1));
				start = i+1;
			}
		}
		sum += Long.parseLong(s.substring(start, s.length()));
		return sum;
	}

}


Measured memory_bytes: 23252
#pragma region Macros
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define REV(x) reverse(ALL(x))
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define SP << " " <<
#define INF2 1000000000000000037
#define INF  1000000007
#define lwb(x,n) distance(x.begin(),lower_bound(ALL(x),(n)))
#define upb(x,n) distance(x.begin(),upper_bound(ALL(x),(n)))
#define fora(i, ...) if(ll i = -1) for(__VA_ARGS__) if(i++, true)
#ifdef _MY_DEBUG
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define de(...) CHOOSE((__VA_ARGS__,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define de(...)
#endif
using namespace std;
using ll = long long;
using ld = long double;
template<class T = ll> using v = vector<T>;
template<class T = ll> using vv = vector<vector<T>>;
template<class T = ll> using vvv = vector<vector<vector<T>>>;
template<class T> bool maxi(T &a, const T &b){ if(a<b){a=b;return 1;}return 0;}
template<class T> bool mini(T &a, const T &b){ if(b<a){a=b;return 1;}return 0;}
template<class T> ll sumer(const T& a){ return accumulate(ALL(a),0LL); }
template<class T> void UNIQUE(vector<T> &a){ SORT(a);a.erase(unique(ALL(a)),a.end());}
template<class T, class U> ostream &operator<<(ostream &os, const pair<T,U> &pe) { os << pe.first << " " << pe.second; return os;}
template<class T> ostream &operator<<(ostream &os, const v<T> &ve) { rep(i,ve.size()) os<< (i?" ":"")<<ve[i]; return os;}
ll topbit(ll a) { return a==0?-1:63-__builtin_clzll(a);}
ll botbit(ll a) { return a==0?64:__builtin_ctzll(a);}
ll popcount(ll a) { return __builtin_popcountll(a);}
#define dame {cout<< retword <<"\n"; return;}
#pragma endregion
//--MODIFS---------------------------------
#pragma region Modifs
#define retword "-1"
#define MOD  1000000007
using P  = pair<ll,ll>;
using TP  = tuple<ll,ll,ll>;
#pragma endregion
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    string S; cin>>S;
    REV(S);
    ll N=S.size();
    ll ans=0;
    ll now=0;
    ll aru[2019]={};
    aru[0]=1;
    ll ima=1;
    rep(i,N){
        now+=ima*(S[i]-'0');
        now%=2019;
        ++aru[now];
        ima*=10;
        ima%=2019;
    }
    rep(i,2019){
        ans+=aru[i]*(aru[i]-1)/2;
        //if(aru[i]>0) de(i,aru[i]);
    }
    cout<< ans <<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // ll Qkai; cin>>Qkai; rep(QQ,Qkai) Main();
    Main();
}
//-----------------------------------------

Measured memory_bytes: 3788
//import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

public class Main<T> {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//System.setIn(new FileInputStream("./input.txt"));
		Reader r = new InputStreamReader(System.in);
		int n = r.read() - 0x30;
		//n = 6;
		//long start = System.nanoTime();
		
		Point[] p = Koch(n);
		//System.out.println((start - System.nanoTime())/ 1000 + " us");
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < p.length; ++i){
			sb.append(p[i] + "\n");
		}
		System.out.println(sb);
	}

	public static Point[] Koch(int n) {
		Point[] p, p2;
		if(n == 0){
			p = new Point[2];
			p[0] = new Point(0.0f, 0.0f);
			p[1] = new Point(100.0f, 0.0f);
			return p;
		}else{
			p = Koch(n-1);
			p2 = new Point[(p.length - 1)*4 + 1];
			for(int i = 0; i < p.length; ++i) {
				// left edge
				p2[i*4] = new Point(p[i].x, p[i].y);
				if(i == p.length - 1){
					break;
				}
				// 3 middle points
				float mx = (p[i+1].x - p[i].x);
				float my = (p[i+1].y - p[i].y);
				
				p2[i*4 + 1] = new Point(mx / 3.0f + p[i].x, my / 3.0f + p[i].y);
				p2[i*4 + 2] = new Point(mx / 2.0f - my / (2.0f * 1.7320508f) + p[i].x,
						my / 2.0f + mx / (2.0f * 1.7320508f) + p[i].y);
				p2[i*4 + 3] = new Point(mx * 2.0f / 3.0f + p[i].x, my * 2.0f / 3.0f + p[i].y);
			}
			return p2;
		}
	}

	
}
class Point {
	public float x;
	public float y;
	@Override
	public String toString(){
		return String.format("%.5f %.5f", x, y);
	}
	public Point(float x, float y){
		this.x = x;
		this.y = y;
	}
}

Measured memory_bytes: 40796
import java.util.*;

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

		int N = scanner.nextInt();

		String line = scanner.next();
		
		int length = 1;
		char a = line.charAt(0);
		for (int i = 1; i < N; i++) {
			if (a != line.charAt(i)) {
				length++;
				a = line.charAt(i);
			}
		}

		System.out.println(length);

	}
}

Measured memory_bytes: 24148
N, Ma, Mb = map(int, input().split())
items = []
for i in range(N):
    a, b, c = map(int, input().split())
    items.append((a, b, c))

a_sum = sum([item[0] for item in items])
b_sum = sum([item[1] for item in items])
inf = float("inf")
dp = [[[inf for _ in range(b_sum + 11)] for _ in range(a_sum + 11)] for i in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
    for a in range(a_sum):
        for b in range(b_sum):
            if dp[i + 1][a][b] > dp[i][a][b]:
                dp[i + 1][a][b] = dp[i][a][b]
            if dp[i + 1][a + items[i][0]][b + items[i][1]] > dp[i][a][b] + items[i][2]:
                dp[i + 1][a + items[i][0]][b + items[i][1]] = dp[i][a][b] + items[i][2]

ans = inf
for a in range(1, a_sum + 1):
    for b in range(1, b_sum + 1):
        if a * Mb == b * Ma:
            ans = min(ans, dp[N][a][b])
if ans != inf:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 96604
N = int(input())
a = list(map(int, input().split()))
boxes = [0] * N
for i in reversed(range(N)):  # i from N-1 to 0
    boxes[i] = (2 + a[i] - sum(boxes[i::i + 1]) % 2) % 2

ansCount = 0
ansIndices = []
for idx, content in enumerate(boxes):
    if content:
        ansCount += 1
        ansIndices.append(idx + 1)

print(ansCount)
if ansCount > 0:
    print(" ".join(map(str, ansIndices)))


Measured memory_bytes: 19892
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>

typedef long long ll;
#define fi first
#define se second

using namespace std;


int main(){
  
  int JN = 1;
  int JE = 1;
  int JS = 1;
  int JW = 1;
  
  char S[1123];
  
  fill( S, S + 1123, '\0' );
  
  scanf("%s", S );
  
  int i;
  
  for( i = 0; i < 1123; i++ ){
         if( S[i] == 'S' ) {JS = 0;}
    else if( S[i] == 'N' ) {JN = 0;}
    else if( S[i] == 'W' ) {JW = 0;}
    else if( S[i] == 'E' ) {JE = 0;}
  }
  
  
  if( ( JS == JN ) && ( JW == JE ) ) puts("Yes");
  else{                              puts("No");}
  
  return 0;
}

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

vector<int> next(vector<int> data){
  for (int i=0; i<data.size(); i++){
    if(data.at(i)==0){
      data.at(i)=1;
      return data;
    }
    else{
      data.at(i)=0;
    }
  }
  return {};
}

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<vector<int>> x(N), y(N);
  int a, b;
  for(int i=0; i<N; i++){
    cin >> A.at(i);
    for(int j=0; j<A.at(i); j++){
      cin >> a >> b;
      x.at(i).push_back(a-1);
      y.at(i).push_back(b);
    }
  }
  int s = 0;
  int ans = 0;
  int X, Y;
  int res = 0;
  vector<int> data(N);
  while(data.size()==N){
    s = 0;
    res = 0;
    for(int i=0; i<N; i++){
      if(data.at(i)==1){
        for(int j=0; j<A.at(i); j++){
          X = x.at(i).at(j);
          Y = y.at(i).at(j);
          if(data.at(X)!=Y){
            s = 1;
          }
        }
      }
    }
    for (int i=0; i<N; i++){
      res += data.at(i);
    }
    if(s==0){
      ans = max(ans,res);
    }
    data=next(data);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int a[5];
inline void read(int &x)
{
	int f;char c;
	for (f=1,c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for (x=0;c<='9'&&c>='0';c=getchar()) x=x*10+(c&15);x*=f;
}
inline int mn(int _x,int _y)
{
	return _x<_y?_x:_y;
}
inline int mx(int _x,int _y)
{
	return _x>_y?_x:_y;
}
inline int ab(int _x)
{
	if(_x<0) return -_x;
	else return _x;
}
inline bool cmp(int p,int q)
{
	return p<q;
}
int main()
{
	read(a[1]);read(a[2]);read(a[3]);
	sort(a+1,a+4,cmp);
	if((a[1]==a[2]&&a[1]!=a[3])||(a[2]==a[3]&&a[1]!=a[3])) printf("Yes\n");
	else printf("No\n");
	return 0;
}



Measured memory_bytes: 256
N = int(input())
ans = 0
for i in range(1,10):
    for j in range(1,10):
        c1 = 0
        c2 = 0
        d = 1
        for x in range(1,N+1):
            if x % (d *10) == 0:
                d = d * 10
        
            if x % 10 == i and x // d == j:
                c1 += 1
            if x % 10 == j and x // d == i:
                c2 += 1
        ans += c1 * c2

print (ans)

Measured memory_bytes: 42844
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#define MN 2000
int n,a,cnt=0;
std::bitset<MN*MN+5> ans;
int main(){
	ans[0]=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a);
		ans|=(ans<<a);
	}
	for(int i=0;i<=MN*MN;i++)
		if(ans[i])cnt++;
	for(int i=0,j=0;i<=MN*MN;i++){
		if(ans[i])j++;
		if(j==(cnt>>1)+1){
			printf("%d",i);
			exit(0);
		}
	}
}

Measured memory_bytes: 1792
/**
  @file e.cpp
  @title E - 1 or 2
  @url https://atcoder.jp/contests/abc126/tasks/abc126_e
**/

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

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

template <class T>
void show(vector<T>& v) {
  for (uint i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << "\n";
}

template <class T>
class UnionFind {
public:
  std::vector<T> par;
  std::vector<T> rank;

  UnionFind(T N)
    : par(N, 0), rank(N, 0) {
    for (T i = 0; i < N; i++) {
      par[i] = i;
      // rank[i] = 0;
    }
  };

  T root(T x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]); // path compression
    }
  }

  bool same(T x, T y) { return (root(x) == root(y)); }

  void unite(T x, T y) {
    T rx = root(x);
    T ry = root(y);
    if (rx == ry)
      return;

    if (rank[rx] < rank[ry]) {
      par[rx] = ry;
    } else {
      par[ry] = rx;
      if (rank[rx] == rank[ry])
        rank[rx]++;
    }
  }

  void show() {
    cout << "index:\t";
    for (uint i = 0; i < par.size(); i++) {
      cout << i << " ";
    }
    cout << "\n";

    cout << "par:\t";
    for (uint i = 0; i < par.size(); i++) {
      cout << par[i] << " ";
    }
    cout << "\n";
  }
};

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

  vector<int> X(M, 0);
  vector<int> Y(M, 0);
  vector<int> Z(M, 0);

  REP(i, M) {
    cin >> X[i] >> Y[i] >> Z[i];
  }

  UnionFind<int> uf(N);

  // REP(i, M) {
  //   if ((Z[i] % 2) == 0) {
  //     uf.unite(X[i], Y[i]);
  //   } else {
  //     uf.unite(X[i], Y[i]);
  //   }
  // }
  REP(i, M) {
    uf.unite(X[i]-1, Y[i]-1);
  }

  int ans = 0;
  REP(i, N) {
    if (uf.root(i) == i) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2176
h,w=map(int,input().split())
s=[]
for _ in range(h):
    s.append(input())

ans='Yes'
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            continue
        if i > 0 and s[i-1][j]=='#':
            continue
        if i < h-1 and s[i+1][j]=='#':
            continue
        if j > 0 and s[i][j-1]=='#':
            continue
        if j < w-1 and s[i][j+1]=='#':
            continue
        ans='No'
        break
    if ans=='No':
        break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> P;

#define pi 3.141592653589793)
#define mod 1000000007

int N, M, X, cnt1, cnt2;
int a[110];

void solve() {
	cin >> N >> M >> X;
	for (int i = 0; i < M; i++) cin >> a[i];

	for (int i = X; i <= N; i++)
		for(int j = 0; j < M; j++)
			if (a[j]== i)cnt1++;

	for(int i = X; i >= 0; i--)
		for (int j = 0; j < M; j++)
			if (a[j] == i)cnt2++;

	cout << min(cnt1, cnt2) << endl;
}

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

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

using namespace std;
long long getabs(long long vl) {
	if(vl<0) return -vl;
	return vl;
}
int main() {
	long long sum[200008];
	sum[0]=0;
	int n;
	cin >> n;
	for(int i=1;i<=n;i++) {
		cin >> sum[i];
		sum[i]+=sum[i-1];
	}
	long long sol=getabs(sum[n]-sum[1]*2);
	for(int i=2;i<n;i++) if(sol>getabs(sum[n]-sum[i]*2)) sol=getabs(sum[n]-sum[i]*2);
	cout << sol << endl;
	return 0;
}


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

int main(){
  int A,B,K;
  cin >> A>>B>>K;
  set<int> l;
  for(int i=0;i<K;++i) if(A+i<=B) l.insert(A+i);
  for (int i=0;i<K;++i) if(B-i>=A) l.insert(B-i);
  for (auto x:l){
    cout << x <<endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<int>A(N+1);
    int sum = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    A[N] = A[0];
    if(sum%((1+N)*N/2)) {
        cout << "NO" << endl;
        return 0;
    }
    int cnt = sum/((1+N)*N/2);
    int res = 0;
    for(int i = 0; i < N; i++) {
        int X = A[i+1]-A[i];
        if(X != cnt) {
            if(X >= cnt) {
                cout << "NO" << endl;
                return 0;
            }
            else if((X-cnt)%N) {
                cout << "NO" << endl;
                return 0;
            }
            res += (X-cnt)/N;
        }
    }
    if(res > N) {
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
}


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

unsigned long long sum1(unsigned long long a){
  if(a % 2 == 0) return ((a / 2) * (a + 1));
  else return (a * ((a + 1) / 2));
}

//Sample
int main()
{
    unsigned long long N;
    cin >> N;
    unsigned long long buf1 = (N - N % 3) / 3;
    unsigned long long buf2 = (N - N % 5) / 5;
    unsigned long long buf3 = (N - N % 15) / 15;
    unsigned long long ans = sum1(N) - sum1(buf1) * 3 - sum1(buf2) * 5 + sum1(buf3) * 15;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define max 100005
#define nil -1

int main() {
	int  n,a,b,c;
	cin >> n>>a>>b>>c;
	cout << n - (a + b) + c << endl;
	
	return 0;
}


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

#define ul unsigned long 
#define ull unsigned long long
#define li long long int

ul f(ul a,ul b) {
  ul ct=0;
  while (a|b) {
    a/=10;b/=10;
    ct++;
  }
  return ct;
}

int main()
{
  ul n,rn,c,m=INFINITY,cf;
  cin >> n;
  rn=(ul)sqrt(n);

  for (ul i=1;i<=rn;i++) {
    if (n%i) continue;
    c=n/i;
    cf=f(c,i);
    if (cf < m) m=cf;
  }

  cout << cf<<endl;

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    map<string,i64> mp;

    rep(i,N){
        string S;
        cin >> S;
        sort(S.begin(),S.end());
        mp[S]++;
    }

    i64 ans = 0;

    for(auto p : mp){
        ans += p.second*(p.second-1)/2; 
    }

    cout << ans << endl;
}


Measured memory_bytes: 11136
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//		String W	 = in.readLine();
//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();

		boolean yes = true;

		for(int i = 0;i<S.length() ; i++) {
			if(S.charAt(i)!=T.charAt(i)) {
				yes = false;
				break;
			}
		}




		if(yes) {
			System.out.println("Yes");
		}else {
		System.out.println("No");
		}

	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}



}


Measured memory_bytes: 35664
/// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int maxn = 2e5+100;

const ll inf = 1e18;

ll Find(ll num){
    ll cnt = 0 , co = num;
    co /= 2;
    while(co > 0){
        cnt += (co/5);
        co /= 5;
    }
    return (cnt);
}

int main()
{

    ll num; cin >> num;
    if(num&1)num = 1;
    cout << Find(num) << endl;
    return 0;
}
/*



*/



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  ll n;cin >>n;
  if(n%2==1){
    cout << 0 << endl;
    return 0;
  }
  ll k =10;
  ll ans = n/k;
  while(n>k){
    k*=5;
    ans+=n/k;
  }
  cout << ans << endl;
}


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

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

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

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

ll N = 0;
ll ret = 0;
string s, t;

int main(void){
  
  IN(s);
  IN(t);
  cout << t << s << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
int a[200],b[200],d[200];
char o[200][5],s[200][5];
int dist[100];
struct edge {
	int a,b,d;
	edge(int _a,int _b,int _d) {a=_a,b=_b,d=_d;}
};
int main() {
	int N,C;
	scanf("%d %d",&N,&C);
	int cnt=0;
	int ans=-3;
	for(int i=0;i<C;i++) {
		scanf("%d%[^0123456789]%d%[^0123456789]%d",&a[i],o[i],&b[i],s[i],&d[i]);
		a[i]--; b[i]--;
		if(o[i][0]=='*') cnt++;
	}
	for(int bit=0;bit<(1<<cnt);bit++) {
		vector<edge> E;
		for(int i=1;i<N;i++) {
			E.push_back(edge(i,0,0));
		}
		int k=0;
		for(int i=0;i<C;i++) {
			if(o[i][0]=='<'||(o[i][0]=='*' && (bit&(1<<k)))) {
				E.push_back(edge(b[i],a[i],0));
				if(s[i][0]=='+') {
					E.push_back(edge(b[i],a[i],-d[i]));
				}else {
					E.push_back(edge(a[i],b[i],d[i]));
				}
			}else if(o[i][0]=='>'||(o[i][0]=='*' && !(bit&(1<<k)))) {
				E.push_back(edge(a[i],b[i],0));
				if(s[i][0]=='+') {
					E.push_back(edge(a[i],b[i],-d[i]));
				}else {
					E.push_back(edge(b[i],a[i],d[i]));
				}
			}
			if(o[i][0]=='*') k++;
		}
		fill(dist,dist+N,1<<29);
		dist[0]=0;
		for(int k=0;k<N;k++) {
			for(int i=0;i<E.size();i++) {
				dist[E[i].b]=min(dist[E[i].b],dist[E[i].a]+E[i].d);
			}
		}
		int res=0;
		for(int i=0;i<N;i++) res=max(res,dist[i]);
		if(dist[0]<0) {
			if(ans==-3) ans=-1;
		}else if(res==1<<29) {
			ans=-2;
		}else {
			if(ans!=-2) ans=max(ans,res);
		}
	}
	if(ans==-2) {
		printf("inf\n");
	}else {
		printf("%d\n",ans);
	}
}

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

int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<10;i++){
        for(int j=i;j<10;j++){
            if(n==i*j){
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}

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

n_list = [i for i in range(4)]

a = n // 1000
b = (n - a * 1000) // 100
c = (n - a * 1000 - b * 100) // 10
d = n - a * 1000 - b * 100 - c * 10

if a == b == c or b == c == d:
    print("Yes")

else:
    print("No")


Measured memory_bytes: 2940
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
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

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn, dt;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int H = getint(), W = getint(), D = getint();
	pair<int, int> A[90001];
	A[0] = mp(0, 0);
	rep(i, H) rep(j, W) {
		A[getint()] = mp(i, j);
	}
	int B[90001];
	rep(i, D) {
		int j = i;
		auto a = mp(0, 0);
		int mae = 0;
		while (j <= H * W) {
			B[j] = (mae += (abs(A[j].first - a.first) + abs(A[j].second - a.second)));
			a = A[j];
			j += D;
		}
	}
	int Q = getint();
	rep(i, Q) {
		int l = getint(), r = getint();
		putint(B[r] - B[l]);
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};
 
using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, W; cin >> n >> W;
    vector<ll> w(n), v(n);
    rep(i, n) cin >> w[i] >> v[i];

    vector<ll> dp(100010);
    ll INF = 1e15;
    rep(i, 100010) dp[i] = INF;
    dp[0] = 0;

    rep(i, n)for(int j = 100010; j >= 0; j--){
        dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
    }
    for(int i = 100010 - 1; i >= 0; i--){
        if(dp[i] <= W){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
map<vi, int> mp;
int sch(vi v, const vvi &ch, int n, int m) {
  if((int)(v.size()) <= 1) return 0;
  int ret = mp[v];
  if(ret > 0) return ret;
  ret = m;
  for(int i=0;i<m;++i) {
    vi left, right;
    for(auto &e: v) {
      if(ch[e][i]) left.push_back(e);
      else right.push_back(e);
    }
    if(!left.empty() && !right.empty()) ret = min(ret, max(sch(left, ch, n, m), sch(right, ch, n, m)) + 1);
  }
  return mp[v] = ret;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    int n, m; cin >> m >> n;
    if(n == 0 && m == 0) break;
    vvi ch(n, vi(m));
    for(int i=0;i<n;++i) {
      string s; cin >> s;
      for(int j=0;j<m;++j) {
        ch[i][j] = s[j] - '0';
      }
    }
    vi v(n);
    for(int i=0;i<n;++i) {
      v[i] = i;
    }
    mp.clear();
    cout << sch(v, ch, n, m) << endl;
  }
}



Measured memory_bytes: 5240
#include <stdio.h>
int main(void){
    int n,m,i,j,a[100][100],b[100],c[100];
    for(i=0,scanf("%d%d",&n,&m);i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(j=0;j<m;j++){
        scanf("%d",&b[j]);
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i]+=a[i][j]*b[j];
        }
    }
    for(i=0;i<n;i++){
        printf("%d\n",c[i]);
    }
}

Measured memory_bytes: 1888
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());
	if (s < t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

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

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll migi = 0, zentai = 0;
    for (int j = i; j < n; j++)
      if (v[i] > v[j]) migi++;
    for (int j = 0; j < n; j++)
      if (v[i] > v[j]) zentai++;

    ans += migi * k % MOD;
    ans %= MOD;
    ans += (k - 1) * k / 2 % MOD * zentai % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


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

int main()
{
    ll n, k;
    cin >> n >> k;
    n = n%k;
    if(abs(n) <= (abs(abs(n)-k))){
        cout << abs(n) << endl;
        return 0;
    }
    cout << (abs(abs(n)-k)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int ans,sum,a[300000],b[300000],n;
map<int,int>m;
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i],b[i]=a[i];
	rep(i,n-1)b[i+1]+=b[i];
	rep(i,n)m[b[i]]++;
	rep(i,n){
		ans+=m[sum];
		m[b[i]]--;
		sum+=a[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
// #include <math.h>
// #include <cmath>
// #include <vector>
// #include <utility> 
// #include <unordered_map>
// #include <map>
// #include <string>

using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;

#define M_PI_H  3.14159265358979323846/2  /* pi by two*/
#define rep(i, start, end) for(int i = start; i < end; i++) 
#define repr(i, start, end) for(int i = start; i >= end; i--)   //INCLUSIVE



int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	
	lli n, d;
	cin>>n>>d;
	lli count=0;
	while(n--){
		lli p, q; cin>>p>>q;
		if(p>d || q>d){
			continue;
		}

		if(p*p + q*q <= d*d){
			count++;
		}
	}
	cout<<count;
    return 0;
}

Measured memory_bytes: 3636
def count_patterns(K,S):
    count_result=0
    for i1 in range(K+1):
        resi1=S-i1
        if resi1<=2*K:
            for i2 in range(resi1+1):
                resi2=resi1-i2
                if i2<=K and resi2<=K:
                    #print(i1,i2)
                    count_result+=1
    return(count_result)

k,s=map(int,input().split(" "))
print(count_patterns(k,s))


Measured memory_bytes: 2940
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define N (ll)(1e6+3)
#define INF (ll)(1e18+3)

#define ll long long
#define rep(i,a,n) for(ll i = a; i < n; i++)
#define per(i,a,n) for(ll i = n-1; i >= a; i--)

//using namespace __gnu_pbds;
using namespace std;
 
// typedef
// tree<
//     pair<ll,ll>,
//     null_type,
//     less<pair<ll,ll>>,
//     rb_tree_tag,
//     tree_order_statistics_node_update>
// ordered_set;

ll a[N];

void fail() {
    cout << "No" << endl;
    exit(0);
}

void done() {
    cout << "Yes" << endl;
    exit(0);
}

void solve() {
    ll n, mx = 0;
    bool b = true;
    cin >> n;
    rep(i,0,n) cin >> a[i];
    rep(i,0,n) {
        mx = max(mx, a[i]);
        if (a[i] != n-1) b = false;
    }

    if (b) done();

    ll cnt = 0;
    rep(i,0,n) {
        if (a[i] < mx) cnt++;
        if (a[i] < mx-1) fail();
    }
    ll low = cnt + 1;
    ll high = cnt + (n-cnt)/2;
    if (low <= mx && high >= mx) done();
    fail();
}


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

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include<math.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
ll mod=1e9+7;

int main(){
	std::vector<pair<string,pair<int,int> > > v;
	int n; cin >>n;
	for(int i=1;i<=n;i++){
		string s; int a; cin >>s>>a;
		v.push_back(make_pair(s,make_pair(-a,i)));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++){
		cout << v[i].second.second << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n, a1, a2;
	float a3, b1, b2;
	
	scanf("%d", &n);
	
	a1 = n % 2;
	a2 = n / 2;
	b1 = a1;
	b2 = a2;
	a3 = (b1 + b2) / n;
	
	printf("%f", a3);
	
	return 0;
}

Measured memory_bytes: 128
# aising2019B - Contests
def main():
    n = int(input())
    A, B = list(map(int, input().rstrip().split()))
    P = sorted(map(int, input().rstrip().split()))
    a, b, c = 0, 0, 0
    for i in P:
        if i <= A:
            a += 1
        elif A < i <= B:
            b += 1
        else:
            c += 1
    print(min(a, b, c))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
/* 
   AOJ 1188
   Hierarchical Democaracy
*/


#include<stdio.h>
#include<stdlib.h>

#define MAX_STR 10001

typedef struct block
{
  int majority, child_num;
  struct block *children[MAX_STR];
}block;


char str[MAX_STR];
int p;



block* new(void)
{
  block* ret = malloc(sizeof(block));
  ret->majority = 0;
  ret->child_num = 0;
  return ret;
}

int parse_num(void)
{
  int ret = 0, n;
  while('0' <= str[p] && str[p] <= '9')
    {
      n = str[p] - '0';
      ret = ret * 10 + n;
      p++;
    }
  return ret;
}

block* parse_block(void)
{
  block* ret = new();
  p++;
  if(str[p] == '[')
    {
      while(str[p] == '[')
	{
	  ret->children[ret->child_num] = parse_block();
	  ret->child_num++;
	  p++;
	}
    }
  else if('0' <= str[p] && str[p] <= '9')
    {
      ret->majority = (parse_num() / 2) + 1;
    }
  return ret;
}

int comp(const void *a, const void *b)
{
  int x = *(int *)a;
  int y = *(int *)b;

  if(x < y)
    return -1;
  else
    return 1;
}

int solve(block* b)
{
  int i;
  int majority_arr[MAX_STR];

  if(b->majority == 0)
    {
      for(i = 0; i < b->child_num; i++)
	majority_arr[i] = solve(b->children[i]);
      qsort(majority_arr, b->child_num, sizeof(int), comp);
      for(i = 0; i < (b->child_num / 2) + 1; i++)
	b->majority += majority_arr[i];
    }

  return b->majority;
}

/* 
----- test case -----
<-input
6
[[123][4567][89]]
[[5][3][7][3][9]]
[[[99][59][63][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]]
[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]
[[[[9][7][3]][[3][5][7]][[7][9][5]]][[[9][9][3]][[5][9][9]][[7][7][3]]][[[5][9][7]][[3][9][3]][[9][5][5]]]]
[[8231][3721][203][3271][8843]]

->output
107
7
175
95
21
3599
---------------------
*/

void print_blocks(block* b)
{
  int i;
  printf("-------block------\n");
  printf("majority = %d, child_num = %d\n", b->majority, b->child_num);
  printf("  ------children------\n");
  for(i = 0; i < b->child_num; i++)
    {
      print_blocks(b->children[i]);
    }
  printf("-------end block----------\n");
}

void free_blocks(block* b)
{
  int i;
  if(b->child_num != 0)
      for(i = 0; i < b->child_num; i++)
	free_blocks(b->children[i]);
  free(b);
  return ;
}

void init(block* head)
{
  free_blocks(head);
  p = 0;
}

int main(void)
{
  int n, i;
  block *head;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%s", str);
      head = parse_block();
      //      print_blocks(head);
      printf("%d\n", solve(head));
      init(head);
    }
  return 0;
}

Measured memory_bytes: 14024
#include<stdio.h>

int main(){

	int m,n1,n2,i,dif,result;
	int p[200];

	while(1){
		scanf("%d %d %d",&m,&n1,&n2);
		if(m==0&n1==0&n2==0){
			break;
		}

		for(i=0;i<m;i++){
			scanf("%d",&p[i]);
		}

		dif=0;

		for(i=n1;i<=n2;i++){
			if(p[i-1]-p[i]>=dif){
				dif=p[i-1]-p[i];
				result=i;
			}
		}

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

}

Measured memory_bytes: 600