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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T> constexpr void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

string s;
void solve() {
    cin >> s;

    if (s == "Sunny") cout << "Cloudy" << endn;
    else if (s == "Cloudy") cout << "Rainy" << endn;
    else cout << "Sunny" << endn;
}

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

    solve();

    cout << flush;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V; 

ll D, G;
ll p[20], c[20];
ll cnt[2000];
static ll cnt_p = 0;

void gcount(ll depth, ll sum, ll slv, V v) {
  if (depth == D) {
    if (sum >= G) {
      cnt[cnt_p] = slv;
      cnt_p++;
    }
    else if (sum < G) {
      int tp = D-1;
      while (v[tp] == 1) {
	tp--;
	if (tp < 0) return;
      }
      REP(i, p[tp]-1) {
	sum += (tp+1)*100;
	if (sum >= G) {
	  slv += (i+1);
	  break;
	}
      }
      if (sum < G) return;
      cnt[cnt_p] = slv;
      cnt_p++;
    }
    return;
  }
  gcount(depth+1, sum, slv, v);
  v[depth] = 1;
  gcount(depth+1, sum+p[depth]*(depth+1)*100+c[depth], slv+p[depth], v);
}

int main() {
  cin >> D >> G;
  REP(i, D) {
    cin >> p[i] >> c[i];
  }
  V v(D, 0);
  gcount(0, 0, 0, v);
  sort(cnt, cnt+cnt_p);
  dump(cnt[0]);
  return 0;
}


Measured memory_bytes: 256
#include <climits>
#include <cstring>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <fstream>
using namespace std;

//Primitive Data Type Stuff
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
#define f first
#define s second

// Number Stuff
const ll INF = 1e18;
int di[] = { 1,-1,0,0 };
int dj[] = { 0,0,1,-1 };
template<class T> void ckmin(T& a, T b) { a = min(a, b); }
template<class T> void ckmax(T& a, T b) { a = max(a, b); }

//For Loop Stuff
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

//Vector and Pair Stuff
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

// IO Stuff
//void setIn(string s) { freopen(s.c_str(), "r", stdin); }
//void setOut(string s) { freopen(s.c_str(), "w", stdout); }
//void setIO(string s = "") {
//	ios_base::sync_with_stdio(0); cin.tie(0);
//	if (sz(s)) { setIn(s + ".in"), setOut(s + ".out"); }
//}
template<class T> void re(T& x) { cin >> x; }
template<class Arg, class... Args> void re(Arg& first, Args& ... rest) { re(first); re(rest...); }
template<class T1, class T2> void re(pair<T1, T2>& p) { re(p.f, p.s); }
template<class T> void re(vector<T>& a) { F0R(i, sz(a)) re(a[i]); }
template<class T, size_t SZ> void re(array<T, SZ>& a) { F0R(i, SZ) re(a[i]); }
template<class T> void pr(const T& x) { cout << x << '\n'; }
template<class Arg, class... Args> void pr(const Arg& first, const Args& ... rest) {
	cout << first << ' '; pr(rest...);
}


const ll MAX_V = 1e5 + 10;
int N;

const ll mod = 1e9 + 7;

ll White[1 + MAX_V];
ll Black[1 + MAX_V];

std::vector<ll> edges[1 + MAX_V];

void dfs(ll v, ll p) {
	Black[v] = 1;
	White[v] = 1;
	for (int c : edges[v])
	{
		if (c == p)
			continue;
		dfs(c, v);
		Black[v] *= White[c];
		Black[v] %= mod;
		White[v] *= (White[c] + Black[c]);
		White[v] %= mod;
	}
}

int main() {
	re(N);
	for (int i = 0; i < N - 1; i++)
	{
		ll a, b;
		re(a, b);
		edges[a].pb(b);
		edges[b].pb(a);
	}
	dfs(1, -1);
	ll answer = (White[1] + Black[1]) % mod;
	pr(answer);
	return 0;
}




Measured memory_bytes: 12800
class SegmentTree: #1-indexed
    def __init__(self,list,f=lambda x,y:x+y,inf=0):
        self.height=(len(list)-1).bit_length()+1 #木の高さ
        self.zero=2**(self.height-1) #最下段に添字を合わせる用
        self.id=inf #単位元
        self.tree=[self.id]*(2**self.height) #木を単位元で初期化
        self.f=f
        for i in range(len(list)):
            self.tree[self.zero+i]=list[i]
        for i in range(self.zero-1,0,-1):
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
        
    def update(self,i,x): #i番目の要素をxに変更
        i+=self.zero
        self.tree[i]=x
        while i>1:
            i//=2
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
    
    def query(self,l,r): #区間[l,r)
        l+=self.zero
        r+=self.zero
        lf,rf=self.id,self.id
        while l<r:
            if l&1:
                lf=self.f(lf,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rf=self.f(self.tree[r],rf)
            l//=2
            r//=2
        return self.f(lf,rf)
 
    '''
    Falseを探索するかTrueを探索するかは問題によって使い分ける(デフォはTrue探索)
    FFFFTTTTとしたときの最小のTを求める
    '''
    def BinarySearch(self,l,r,f): #fの返り値はboolにする
        if not f(self.query(l,r)):
            return r+1
        l+=self.zero
        r+=self.zero
        while True:
            if f(self.tree[l]):
                if l>=self.zero:
                    return l-self.zero+1 #最下段ならreturn
                else:
                    l*=2 #左の子供を見る
            else:
                if l%2==0:
                    l+=1 #左の子なら右を見る
                else:
                    l=(l//2)+1 #右の子なら親の右を見る
 
#####################################################
 
n,q=map(int,input().split())
a=list(map(int,input().split()))
seg=SegmentTree(a,max)
for i in range(q):
    t,x,y=map(int,input().split())
    if t==1:
        seg.update(x-1,y)
    elif t==2:
        print(seg.query(x-1,y))
    else:
        print(seg.BinarySearch(x-1,n,lambda x:x>=y))

Measured memory_bytes: 31464
use std::io;
use std::collections::HashMap;

fn main()  {
    let mut line = String::new();
    io::stdin().read_line(&mut line).ok();
    let N = line.trim().parse::<i64>().unwrap();
    let mut A_hash: HashMap<i64, i64> = HashMap::new();
    for i in 0..N{
        let mut line = String::new();
        io::stdin().read_line(&mut line).ok();
        let a = line.trim().parse::<i64>().ok().unwrap(); 
        A_hash.insert(i, a);
    }

    let mut A_vec: Vec<_> = A_hash.iter().collect();
    A_vec.sort_by(|a, b| b.1.cmp(a.1));

    let max_index = A_vec[0].0;
    let max_num = A_vec[0].1;
    let second_max_num = A_vec[1].1;

    for i in 0..N{
        if i == *max_index{
            println!("{}", second_max_num);
        }
        else{
            println!("{}", max_num);
        }
    }
}


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

#define N 100

int main(void){
  int n, A[N];
  int i, j, min_i, cnt=0;

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d", A+i);

  for(i=0; i<n-1; i++){
    min_i=i;
    for(j=i+1; j<n; j++){
      if(A[min_i]>A[j]){
	min_i=j;
      }
    }
    if(i!=min_i){
      swap(A[i], A[min_i]);
      cnt++;
    }
  }

  for(i=0; i<n; i++){
    if(i) printf(" %d", A[i]);
    else  printf("%d", A[i]);
  }

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

  return 0;
}



Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
	int n,k=1,anss,i;
	bool flag,ress=false;
	scanf("%d",&n);
	scanf("%d",&a[0]);
	if(n==1)
	{
		printf("1\n");
		return 0;
	}
	anss=a[0];
	for(i=1;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(!ress)
		{
			if(a[i]>anss)
			{
				flag=true;
				ress=true;
				anss=a[i];
			}
			else if(a[i]<anss)
			{
				flag=false;
				ress=true;
				anss=a[i];
			}
		}
		else
		{
			if(flag)
			{
				if(a[i]>=anss)
					anss=a[i];
				else
				{
					k++;
					anss=a[i];
					ress=false;
				}
			}
			else
			{
				if(a[i]<=anss)
					anss=a[i];
				else
				{
					k++;
					anss=a[i];
					ress=false;
				}
			}
		}
	}
	cout<<k<<endl;
	
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int acount=0,bcount=0;
	string s;
  cin >>s;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if (s[i]=='0')acount++;
      else if (s[i]=='1') bcount++;
    }
    else{
      if(s[i]=='0')bcount++;
      else if(s[i]=='1') acount++;
    }
  }
  cout << min(acount,bcount)<<endl;
}

Measured memory_bytes: 512
N,M,X,*A=map(int,open(0).read().split())

I=lambda p,q:p.index(q)

if X in A:
    print(min(I(A,X),M-I(A,X)-1))
else:
    A.append(X)
    A=sorted(A)
    print(min(I(A,X),M-I(A,X)))

Measured memory_bytes: 3060
L,R=gets.chomp.split.map(&:to_i)

ans=2020
if R-L>=2019
  puts 0
  exit
else
  L.upto(R) do |i|
    (i+1).upto(R) do |j|
      ans = (i*j)%2019 if ans > (i*j)%2019
    end
  end
end

puts ans

Measured memory_bytes: 1916
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

int a[100005];

signed main(){
	
	rep(i,100005) a[i] = 0;
	int n;cin>>n;
	rep(i,n) 
	{
		int x;cin>>x;
		a[x]++,a[x+1]++,a[x+2]++;
	}
	int ans = -1;
	rep(i,100004) ans = max(ans,a[i]);
	cout << ans << endl;
	
}
 

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

int main(){
    int A, B, C, D;
    std::cin >> A >> B >> C >> D;
    
    bool turn = false;
    while(A > 0 && C > 0){
        if(turn){
            A -= D;
            turn = false;
        }else{
            C -= B;
            turn = true;
        }
    }
    if(A <= 0){
        std::cout << "No" << std::endl;
    }else{
        std::cout << "Yes" << std::endl;
    }
    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main()
{
	int x , y , count = 0;
	cin >> x >> y;
	int arr;
	for (int i = 0 ; i < x ; i++)
	{
		cin >> arr;
		if (arr > y || arr == y)
		{
			count++;
		}
	}
	cout << count;
}

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

int main() {
    int N;
    string S;
    bool hasY = false;

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> S;
        if (S == "Y") {
            hasY = true;
        }
    }

    string out = "Three";
    if (hasY) {
        out = "Four";
    }

    if (N >= 3) {
        cout << out << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> in(n, 0);
    vector<vector<int>> G(n);
    for (int i = 0; i < n-1+m; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].emplace_back(b-1);
        in[b-1]++;
    }
    vector<int> visited(n, 0);
    vector<int> ans(n, -1);
    int par = -1;
    for (int i = 0; i < n; ++i) {
        if(in[i] == 0) par = i;
    }
    deque<int> d;
    d.emplace_back(par);
    while(!d.empty()){
        int p = d.front(); d.pop_front();
        if(visited[p]) continue;
        visited[p] = 1;
        for (auto &&i : G[p]) {
            ans[i] = p;
            if(in[i] == 1) d.emplace_back(i);
            in[i]--;
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%d\n", ans[i]+1);
    }
    return 0;
}


Measured memory_bytes: 7424
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define MIN(a,b) ((a < b) ? a : b)

static int DefNum[3][30];
static int Cost[3][30];
static int CD[500][500];

int main(void) {
  int N, C;
  scanf("%d%d", &N, &C);
  for(int i = 0; i < C; i++) {
    for(int j = 0; j < C; j++) {
      scanf("%d", &CD[i][j]);
    }
  }
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= N; j++) {
      int c;
      scanf("%d", &c);
      int mod3 = (i+j) % 3;
      DefNum[mod3][c-1]++;
    }
  }

  for(int m = 0; m < 3; m++) {
    for(int i = 0; i < C; i++) {// from
      for(int j = 0; j < C; j++) {// to
	Cost[m][j] += DefNum[m][i] * CD[i][j];
      }
    }
  }

  int Ans = INT_MAX;
  for(int x = 0; x < C; x++) {
    for(int y = 0; y < C; y++) {
      if(x == y) continue;
      for(int z = 0; z < C; z++) {
	if(z == x || z == y) continue;
	int tmp = Cost[0][x] + Cost[1][y] + Cost[2][z];
	Ans = MIN(Ans, tmp);
      }
    }
  }
  printf("%d\n", Ans);
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
reds = []
blues = []
counter = 0

n.times.each do
  x, y = gets.chomp.split.map(&:to_i)
  reds.push(x: x, y: y)
end

n.times.each do
  x, y = gets.chomp.split.map(&:to_i)
  blues.push(x: x, y: y)
end

reds.sort! { |a, b| a[:x] <=> b[:x] }
blues.sort! { |a, b| a[:x] <=> b[:x] }

blues.each do |blue|
  candidates = reds.select { |red| red[:x] < blue[:x] }.sort { |a, b| a[:y] <=> b[:y] }.reverse
  candidates.each do |c|
    next unless c[:y] < blue[:y]
    counter += 1
    reds.delete c
    break
  end
end

puts counter

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize
#define ini ll_MAX
#define inl LLONG_MAX
#define MOD 1000000007
#define sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define F0R(i, a) for (ll i = 0; i < (a); i++)
#define FORR(i, a, b) for (ll i = a; i >= (b); i--)
#define F0RR(i, a) for (ll i = a; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define pbds tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
 
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
 
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;
 
ll mod(ll a,ll b)
{
    return (b+a%b)%b;
}
 
ll gcd(ll a,ll b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
ll po(ll a,ll b)
{
    ll ans = 1;
    while(b--)
        ans*=a;
    return ans;
}

ll power(ll x, ll y, ll p)  
{  
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}  
 
double sqdist(double a,double b,double c,double d)
{
    return (a-c)*(a-c)+(b-d)*(b-d);
}
ll fact(ll n)
{
    if(n==0)return 1;
    ll ans = 1;
    FOR(i,1,n+1)ans*=i;
    return ans;
}
 


void solve()
{
    string a,b;
    cin>>a>>b;
    int p = a.size(),q=b.size();
    if(p==q-1&&b.substr(0,p)==a)cout<<"Yes";
    else cout<<"No";
}   
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();
}

Measured memory_bytes: 3612
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
	Scanner in =new Scanner(System.in);

	int n,x;
	while(true){
	    n = in.nextInt();
	    x = in.nextInt();

	    if(n==0 && x==0)break;
	    int cnt=0;
	    for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
		    for(int k=j+1;k<=n;k++){
			if((i+j+k)==x)cnt++;
		    }
		}
	    }
	    System.out.println(cnt);
	}
    }
}
		    



Measured memory_bytes: 27124
#include<iostream>
#include<vector>
int main(){
    long long int n;
    long long int profit;
    profit=-999999999999;
    std::cin>>n;
    std::vector<long long int>a(n),a_min(n);
    for(long long int i=0;i<n;i++){
        std::cin>>a.at(i);
        if(i==0){
            a_min.at(0)=a.at(0);
        }else{
            a_min.at(i)=std::min(a.at(i),a_min.at(i-1));
        }
    }
    for(long long int i=1;i<n;i++){
        profit=std::max(profit,a.at(i)-a_min.at(i-1));
    }
    std::cout<<profit<<std::endl;
    return 0;
}


Measured memory_bytes: 5888
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int m = stdIn.nextInt();
		int[]a = new int[m];
		long cnt = 0;
		for(int i = 0; i < m; i++) {
			a[i] = stdIn.nextInt();
			cnt += a[i];
		}
		
		if(n>=cnt) {
			System.out.println(n-cnt);
		}else {
			System.out.println(-1);
		}
		
	}

}


Measured memory_bytes: 46208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n; cin>>n;
    vector<vector<ll>> tree(n);
    vector<ll> parent(n, -1), depth(n, -1);
    rep(i,n){
        ll id,k; cin>>id>>k;
        rep(j,k){
            ll c; cin>>c;
            tree[id].push_back(c);
            parent[c]=id;
        }
    }
    ll root;
    rep(i,n) if(parent[i]==-1) root=i;
    queue<ll> que;
    que.push(root);
    depth[root]=0;
    while(!que.empty()){
        ll x=que.front();
        que.pop();
        for(ll y: tree[x]){
            depth[y]=depth[x]+1;
            que.push(y);
        }
    }
    rep(i,n){
        cout<<"node "<<i<<": ";
        cout<<"parent = "<<parent[i]<<", ";
        cout<<"depth = "<<depth[i]<<", ";
        if(parent[i]==-1) cout<<"root";
        else if(tree[i].empty()) cout<<"leaf";
        else cout<<"internal node";
        cout<<", [";
        rep(j, tree[i].size()){
            if(j!=0) cout<<", ";
            cout<<tree[i][j];
        }
        cout<<"]"<<endl;
    }
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N, D; cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    rep(i, N) rep(j, D) cin >> X[i][j];

    int ans = 0;
    rep(y, N-1) REP(z, y+1, N) {
        double dist_d = 0;
        rep(i, D) dist_d += pow(abs(X[y][i] - X[z][i]), 2);
        dist_d = sqrt(dist_d);
        int dist_i = dist_d;
        if (dist_d == dist_i) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np

n, m, c = map(int, input().split())
arr = list(map(int, input().split()))
mtr = []
for i in range(n):
    a = list(map(int, input().split()))
    mtr.append(a)

count = 0
for i in range(n):
    if np.dot(mtr[i], arr)+c > 0:
        count += 1
print(count)

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D ;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#import sys
#input = sys.stdin.readline
Q = 10**9+7
def main():
    N, K = map( int, input().split())
    A = list( map( int, input().split()))
    if K == 1:
        print(max(A))
        return
    positive = 0
    zero = 0
    negative = 0
    for a in A:
        if a > 0:
            positive += 1
        elif a == 0:
            zero += 1
        else:
            negative += 1
    # print(positive, negative, zero)
    # print(positive+negative, K)
    if positive+negative < K:
        print(0)
        return
    if positive == 0:
        if K%2 == 1:
            if zero > 0:
                print(0)
                return
            else:
                A.sort(reverse=True)
                ans = 1
                for a in A[:K]:
                    ans *= a
                    ans %= Q
                print(ans)
                return
        else:
            A.sort()
            ans = 1
            for a in A[:K]:
                ans *= a
                ans %= Q
            print(ans)
            return
    # if K == 2:
    #     if negative <= 1:
    #         A.sort(reverse=True)
    #         print(A[0]*A[1]%Q)
    #         return
    if negative <= 1:
        A.sort(reverse=True)
        ans = 1
        for a in A[:K]:
            ans *= a
            ans %= Q
        print(ans)
        return
    if K == negative + positive:
        if negative%2 == 1:
            if zero > 0:
                print(0)
                return
        ans = 1
        for a in A:
            if a != 0:
                ans *= a
                ans %= Q
        print(ans)
        return
    B = [(abs(a), a) for a in A]
    B.sort(reverse = True)
    minus = False
    minus_value = 0
    plus_value = 0
    ans = 1
    for b in B[:K]:
        ans *= b[0]
        ans %= Q
        if b[1] < 0:
            minus = not minus
            minus_value = b[0]
        elif b[1] > 0:
            plus_value = b[0]
    # print(plus_value, minus_value)
    if minus:
        ans_plus = ans_minus = ans
        plus_replaced_value = 0
        minus_replaced_value = 0
        if minus_value > 0:
            for b in B[K:]:
                if b[1] > 0:
                    ans_plus = ans*pow(minus_value,Q-2,Q)%Q*b[0]%Q
                    if plus_value == 0:
                        plus_replaced_value = b[0]
                    else:
                        plus_replaced_value = plus_value*b[0]
                    break
        if plus_value > 0:
            for b in B[K:]:
                if b[1] < 0:
                    ans_minus = ans*pow(plus_value,Q-2,Q)%Q*b[0]%Q
                    if minus_value == 0:
                        minus_replaced_value = b[0]
                    else:
                        minus_replaced_value = minus_value*b[0]
                    break
        if plus_replaced_value == 0 and minus_replaced_value == 0:
            pass
        elif plus_replaced_value < minus_replaced_value:
            ans = ans_minus
        else:
            ans = ans_plus
    # print(plus_replaced_value, minus_replaced_value)
    # print(ans, ans_minus, ans_plus)
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 39652
#include<stdio.h>

int main()
{

	char b, c;

	scanf("%c", &b);

	if (b == 'A')c = 'T';
	if (b == 'T')c = 'A';
	if (b == 'C')c = 'G';
	if (b == 'G')c = 'C';







	printf("%c", c);


	return(0);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

int main(){
	double N, D;
	cin >> N >> D;
	cout << ceil(N /(2 * D + 1)) << endl;
}


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

typedef long long int ll;


ll sol(const vector<int> &fs, const vector<int> &ss, const vector<int> &ts) {
    ll ret = 0;
    for (int i = 0; i < (int)fs.size(); i++) {
        int f = fs[i];
        auto it = upper_bound(ss.begin(), ss.end(), f);
        for (; it != ss.end(); it++) {
            int tmp = 0;
            int s = *it;

            int invalid_k = s + s - f;
            auto t_it = upper_bound(ts.begin(), ts.end(), s);
            tmp = ts.end() - t_it;
            auto tmp_it = lower_bound(ts.begin(),ts.end(), invalid_k);
            if (tmp_it != ts.end() && tmp_it >= t_it && *(tmp_it) == invalid_k) {
                tmp--;
            }
            ret += tmp;
        }
    }
    return ret;
}

int main () {
    int n; cin >> n;
    string str; cin >> str;

    vector<int> rs(0);
    vector<int> gs(0);
    vector<int> bs(0);

    for (int i = 0; i < (int)str.size(); i++) {
        if (str[i] == 'R') {
            rs.push_back(i + 1);
        } else if (str[i] == 'G') {
            gs.push_back(i + 1);
        } else {
            bs.push_back(i + 1);
        }
    }

    ll ans = 0;
    ans += sol(rs, gs, bs);
    ans += sol(rs, bs, gs);
    ans += sol(gs, rs, bs);
    ans += sol(gs, bs, rs);
    ans += sol(bs, rs, gs);
    ans += sol(bs, gs, rs);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3208
#include <iostream>

int main(){
	int n;
	int m;
	int A[100][100];
	int b[100];
	int c[100]={};
	std::cin>>n;
	std::cin>>m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			std::cin>>A[i][j];
		}
	}
	for(int i=0;i<m;i++){
		std::cin>>b[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			c[i]+=A[i][j]*b[j];
		}
		std::cout<<c[i]<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1196
/*******************************\
   Name:    REAJUL HAQUE REAYZ  |
   School:  COMILLA UNIVERSITY  |
            CSE (5TH BATCH)     |
********************************/
#include<bits/stdc++.h>
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define mem(x,y) memset(x , y , sizeof(x))
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const ll MOD = 1000000007;
const int MAX = 200005;

ll n, a[MAX], b[MAX];
int call(int x, int y)
{
    ll sum=b[y]-b[x-1];
    sum=(sum+1)/2;
    sum=sum+b[x-1];
    ll from=x, high=y;
    while(from<high){
        ll mid=(from+high+1)/2;
        if(b[mid]<=sum) from=mid;
        else high=mid-1;
    }
    if(abs((b[from]-b[x-1])-(b[y]-b[from]))<=abs((b[from+1]-b[x-1])-(b[y]-b[from+1])) ) return from;
    else return from+1;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(ll i=1; i<=n; i++) cin>>a[i];
    for(ll i=1; i<=n; i++) b[i]=a[i]+b[i-1];
    ll ans=1e18;
    for(ll j=2; j<=n-2; j++){
        ll i = call(1, j);
        ll k = call(j+1, n);
        ll arr[4];
        arr[0]=b[i];
        arr[1]=b[j]-b[i];
        arr[2]=b[k]-b[j];
        arr[3]=b[n]-b[k];
        sort(arr,arr+4);
        ans = min(ans, arr[3]-arr[0]);
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3328
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

long rup(long x, long y)
{
    if (x % y == 0)
        return x;
    return (x / y) * y + y;
}

long rdn(long x, long y)
{
    if (x % y == 0)
        return x;
    return (x / y) * y;
}

int main()
{
    int K;
    cin >> K;
    vector<long> A(K);
    for (long& a : A)
        cin >> a;
    reverse(A.begin(), A.end());

    if (A[0] != 2) {
        cout << "-1\n";
        return 0;
    }

    long lb = 2;
    long ub = 2;
    for (long a : A) {
        long nlb = rup(lb, a);
        long nub = rdn(ub, a) + a - 1;
        lb = nlb;
        ub = nub;
        // cerr << lb << ", " << ub << endl;
        if (lb > ub) {
            cout << "-1\n";
            return 0;
        }
    }

    cout << lb << ' ' << ub << '\n';

    return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define rep2(i,r,l) for(int i=r;i>=l;i--)
#define sz(a) (ll)a.size()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define nl "\n"
#define pii pair<ll,ll>
#define F first
#define S second
#define iterate(c,x) for(auto &x:c)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define trace(...)
#endif
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
// less_equal
// ordered_set X;
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	int n;
	cin>>n;
	vector<int> h(n), dp(n);
	for(int i = 0; i < n; i++)
		cin>>h[i];
	dp[n-1] = 0;
	dp[n-2] = abs(h[n-2]-h[n-1]);
	for(int i = n-3; i >= 0; i--){
		dp[i] = min( abs(h[i]-h[i+1])+dp[i+1], abs(h[i]-h[i+2])+dp[i+2]);
	}
	cout<<dp[0]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	/*int x;
	cin >> x;
	if (x >= 30)puts("Yes");
	else puts("No");*/


	/*ll n, d;
	cin >> n >> d;
	int ans = 0;
	ll x, y;
	rep(i, n) {
		cin >> x >> y;
		if (sqrt(x * x + y * y) <= d)ans++;
	}
	cout << ans;*/


	int k;
	cin >> k;
	if (k % 2 == 0)puts("-1");
	else {
		int a = 7;
		int ans = 1;
		vector<int>p(k);
		while (a % k != 0) {
			if (p[a]) {
				ans = -1;
				break;
			}
			p[a] = 1;
			a = a * 10 + 7;
			a = a % k;
			ans++;
		}
		cout << ans;
	}


	/*int n;
	cin >> n;
	string s;
	cin >> s;
	int wnum = 0;
	rep(i, n) {
		if (s[i] == 'W')wnum++;
	}
	rep(i, n) {
		if (s[i] == 'W' && i > n - 1 - wnum)wnum--;
	}
	cout << wnum;*/
	return 0;
}

Measured memory_bytes: 7212
import java.util.*;

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

        int K = sc.nextInt();
        int S = sc.nextInt();
        int ans = 0;

        for(int i=0; i<=K; i++){
            int X = i;
            for(int j=0; j<=K; j++){
                int Y = j;
                if(S-X-Y>=0 && S-X-Y<=K){
                    ans += 1;
                }
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 21716
import java.util.Scanner

import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer


object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val seqBuf = ArrayBuffer.empty[Int]
    for (i <- 0 until n) {
      val elem = sc.nextInt()
      seqBuf.append(elem)
    }
    (n, seqBuf.toVector)
  }

  // 長さlengthの半開区間の部分半開区間の数
  def numSubsection(length: Int): Long = length.toLong * (length.toLong + 1) / 2

  // 半開区間[left, right)の部分半開区間の数
  def numSubsection(left: Int, right: Int): Long = numSubsection(right - left)


  /**
    * 次のようなリストlistを返す
    * list(l) = max{r | satisfies(l, r)} (l=0,1,...,n-1)
    *
    * @param satisfies satisfies(l,r) ならば satisfies(l+1, r), satisfies(l, r-1)
    * @param n         >0
    */
  def maxRightSatisfies(satisfies: (Int, Int) => Boolean, n: Int): Vector[Int] = {
    @tailrec
    def hoge(l: Int, r: Int, acc: List[Int]): List[Int] = {
      if (l == n) acc
      else if (r <= n && satisfies(l, r)) hoge(l, r + 1, acc)
      else hoge(l + 1, r, (r - 1) :: acc)
    }

    hoge(0, 0, Nil).reverse.toVector
  }

  def solve(n: Int, seq: Vector[Int]): Long = {
    // comulativeSum(k) = seq(0) + seq(1) + ... + seq(k-1)
    val cumulativeSum: Vector[Long] = seq.scanLeft(0: Long)(_ + _)
    val cumulativeXor: Vector[Long] = seq.scanLeft(0: Long)(_ ^ _)

    // seqの[left, right)の項の通常の和を求める
    // seq(left) + ... + seq(right-1) = (seq(0) + ... + seq(right-1)) - (seq(0) + ... + seq(left-1))
    def partialSum(left: Int, right: Int): Long = cumulativeSum(right) - cumulativeSum(left)

    // seqの[left, right)の項のXORの和を求める
    // XOR(^)の逆演算はXOR(^)
    def partialXor(left: Int, right: Int): Long = cumulativeXor(right) ^ cumulativeXor(left)

    // [right, left)の項の通常和 = [right, left)の項のXOR和
    val satisfies = (left: Int, right: Int) => partialSum(left, right) == partialXor(left, right)

    // maxRightList(l) = max{r | satisfies(l, r)}
    val maxRightList = maxRightSatisfies(satisfies, n)

    (0 until n).map(l => numSubsection(l, maxRightList(l))).sum - (1 until n).map(l => numSubsection(l, maxRightList(l - 1))).sum
  }

  def main(args: Array[String]): Unit = {
    val (n, seq) = read()
    println(solve(n, seq))
  }
}

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


int n;
std::string str;


std::string substg(int a, int b) {
	std::string res = "";
	for (int i = a; i < a + b; i++) {
		res += str[i];
	}

	return res;
}

void replace(int a) {
	std::string hoge = "Hoshina";

	for (int i = a; i < a + 7; i++) {
		str[i] = hoge[i - a];
	}
}

void solve() {
	int i = 0;
	while (i <= (signed)(str.size() - 7)) {
		if (substg(i, 7) == "Hoshino") {
			replace(i);
			i += 7;

			continue;
		}

		i++;
	}

	std::cout << str << std::endl;
}




int main() {
	std::cin >> n;

	std::cin.ignore();

	for (; n > 0; n--) {
		std::getline(std::cin, str);

		solve();
	}

	return 0;
}


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

int main() {
  int a,b[200010],c[200010];
  cin >> a ;
  
  for(int i=0;i<a-1;i++)
    cin >> b[i];
  
  for(int i=0;i<200010;i++){
    c[i] = 0;
  }
  
  for(int i=0;i<a-1;i++){
    c[b[i]]++;
  }

  for(int i=1;i<=a;i++){
cout << c[i] << endl;
  }
  
}


Measured memory_bytes: 5200
#include <algorithm>
#include <stdio.h>

struct katana{long long a, b, i;} n[100100];

bool lt(katana a, katana b) {
	return a.b != b.b ? a.b > b.b : a.a > b.a;
}

int main() {
	long long N, H, i, mi, ma, sb, t;
	for (scanf("%lld%lld", &N, &H), mi = i = 0; i != N; i++)
		scanf("%lld%lld", &n[i].a, &n[i].b), n[mi].a < n[i].a && (mi = i);
	for (ma = n[mi].a, std::sort(n, n+N, lt), t = sb = i = 0; i != N; i++)
		n[i].b > ma && (sb += n[i].b, t++);
	if (sb >= H) {
		for (i = 0; H > 0; i++)
			H -= n[i].b;
		printf("%lld\n", i);
	}
	else
		printf("%lld\n", (H-sb)/ma+((H-sb)%ma ? 1 : 0)+t);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
using ll = long long;
int main()
{
	int a,b,c;
    cin >> a >> b >> c;
    
    int k;
    cin >> k;
    
    int cnt = 0;
    while(b <= a)
    {
        b*=2;
        cnt++;
    }
    while(c <= b)
    {
        c*=2;
        cnt++;
    }
    
    if(cnt <= k)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
	return 0;
}

Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N; cin >> N;
    vector<ll> a;
    int x;
    FOR(i,0,N){
        cin >> x;
        a.push_back(x);
    }
    vector<ll> b(N);
    b[0] = a[0];
    FOR(i,1,N){
        b[i]=b[i-1]+a[i];
    }
    ll res = INF;
    FOR(i,0,N-1){
        res = min(res,abs(b[N-1]-2*b[i]));
    }
    cout << res << endl; 
    return 0;
}

Measured memory_bytes: 3440
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public final class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s = new Scanner(System.in);
		long a = s.nextLong();
		long b = s.nextLong();
		HashSet<Long> set = new HashSet<>();
        System.out.println(printAllDivisors(a,b,set)+1);
	}
    public static long gcd(long a, long b) 
    { 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
    } 
    public static long printAllDivisors(long a,long b ,HashSet<Long> divisors) 
    {    
    long g = a; 
        g = gcd(b, g); 
 
        for (long i = 1; i * i <= g; i++) 
        { 
            if (g % i == 0)  
            { 
                divisors.add(i); 
                if (g / i != i) 
                    divisors.add(g / i); 
            } 
        }
        long ans = 0;
        for(long i : divisors){
            if(isPrime(i)){
                ans++;
            }
        }
        return ans;
    }
    static boolean isPrime(long n) 
    { 
        // Corner cases 
        if (n <= 1) return false; 
        if (n <= 3) return true; 
      
        // This is checked so that we can skip  
        // middle five numbers in below loop 
        if (n % 2 == 0 || n % 3 == 0) return false; 
      
        for (long i = 5; i * i <= n; i = i + 6) 
            if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
      
        return true; 
    }
}

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

struct Point { double x, y; };
int n;
double ans = 10000;
vector<Point> ps;

double dist(Point a, Point b) {
  double dx = a.x-b.x;
  double dy = a.y-b.y;
  return sqrt(dx*dx + dy*dy);
}

double f( double x, double y ) {
    double res = 0;
    for ( int i=0; i<n; i++  ) {
        res = max(res, dist(ps[i], (Point){x,y}));
    }
    return res;
}

double g( double x ) {
    double l=0, r=1000, mi=10000;
    for ( int k=0; k<50; k++ ) {
        double y1 = (l+l+r)/3;
        double y2 = (l+r+r)/3;
        double res1 = f(x, y1);
        double res2 = f(x, y2);
        mi = min({mi, res1, res2});
        if ( res1 > res2 ) l=y1;
        else r=y2;
    }
    ans = min(ans, mi);
    return mi;
}

int main() {
    cin >> n;
    ps.resize(n);
    for ( int i=0; i<n ; i++ ) {
        cin >> ps[i].x >> ps[i].y;
    }
    // 三分探索
    double l=0, r=1000;
    for ( int k=0; k<50; k++ ) {
        double x1 = (l+l+r)/3;
        double x2 = (l+r+r)/3;
        if ( g(x1) > g(x2) ) l=x1;
        else r=x2;
    }
    cout << fixed << setprecision(12) << ans << '\n';
    return 0;
}

Measured memory_bytes: 3820
#include<stdio.h>
#include<string.h>
int main(void){
    int sum;
    int i;
    char str[1100];
    for(i=0; i<1100; i++){
       str[i] = 0;
    }
    while(1){
        scanf(" %s", str);
        if(strcmp(str, "0") == 0){
            break;
        }
        sum = 0;
        for(i=0; str[i]!='\0';i++){
            sum+= str[i] - '0';
       }
        printf("%d\n", sum);
    }
    return 0;
}

Measured memory_bytes: 536
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,n,s) for(int i=s;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  if(s[k-1] == 'A') {
    s[k-1] = 'a';
  } else if(s[k-1] == 'B') {
    s[k-1] = 'b';
  } else {
    s[k-1] = 'c';
  }

  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
import           Control.Monad

readWordsLn :: Read a => IO [a]
readWordsLn = map read . words <$> getLine

main :: IO ()
main = do
    [n, t] <- readWordsLn :: IO [Int]
    cts    <- replicateM n readWordsLn :: IO [[Int]]
    let minRoute = foldl (calcMinRoute t) (Left "TLE") cts
    either putStrLn (print . head) minRoute
  where

    calcMinRoute :: Int -> Either String [Int] -> [Int] -> Either String [Int]
    calcMinRoute t (Right ct0@[c0, t0]) ct1@[c1, t1] =
        if c1 < c0 && t1 <= t then Right ct1 else Right ct0
    calcMinRoute t (Left tle) ct1@[c1, t1] =
        if t1 <= t then Right ct1 else Left tle

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

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

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    ostr << p.first << " " << p.second;
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
// vll x(n); x[i]=a;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
#define INF 1e+12
#define EPS 1e-12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x))

ll bfs(vvc &s, ll h, ll w, ll x, ll y){
    ll qx = x, qy = y, nx, ny, ans = 0;
    vll dx{1, -1, 0, 0}, dy{0, 0, 1, -1};
    vvll v(h, vll(w, 0)); v[x][y] = 1;
    vpll qu(1, pll {qx,qy});

    while(qu.size()){
        vpll qu_new;
        REP(i,qu.size()){
            qx = qu[i].first;
            qy = qu[i].second;

            REP(j,4){
                nx = qx+dx[j];
                ny = qy+dy[j];
                if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
                if (s[nx][ny] == '#' || v[nx][ny] == 1) continue;
                qu_new.emplace_back(pll {nx, ny});
                v[nx][ny] = 1;
            }
        }
        qu = qu_new;
        ans++;
    }
    ans--;
    return ans;
}

int main(){
    ll h, w, len, ans = 0;
    cin >> h >> w;
    vvc s(h, vc(w));
    cin >> s;

    REP(i,h){
        REP(j,w){
            if(s[i][j] == '#') continue;
            len = bfs(s, h, w, i, j);
            if(len > ans) ans = len;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    S = input()
    Q = int(readline())
    K = list(map(int, readline().split()))

    for q in range(Q):
        k = K[q]
        res = 0
        cnt = [0] * 3
        for i in range(k):
            cur = S[i]
            if cur == "D":
                cnt[0] += 1
            elif cur == "M":
                cnt[1] += 1
                cnt[2] += cnt[0]
            elif cur == "C":
                res += cnt[2]

        for i in range(k, N):
            prev = S[i - k]
            cur = S[i]
            if prev == "D":
                cnt[0] -= 1
                cnt[2] -= cnt[1]
            elif prev == "M":
                cnt[1] -= 1

            if cur == "D":
                cnt[0] += 1
            elif cur == "M":
                cnt[1] += 1
                cnt[2] += cnt[0]
            elif cur == "C":
                res += cnt[2]
        print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 76388
program xor_sum4
    implicit none
    integer(8),parameter:: md = 1000000007
    integer(4):: i,j,k
    integer(4):: n
    integer(8),allocatable::a(:), total_bits(:)
    integer(8):: ans=0, dmp=0
    
    read*, n
    allocate(a(n))
    allocate(total_bits(0:61), source=0_8)
    read*,a(:)

    do i=1,n
        do j=0,61
            if (btest(a(i),j)) total_bits(j) = total_bits(j) + 1_8
        end do
    end do
    
    do i=0,61
        dmp=1_8
        do j=1,i
            dmp = mod(dmp*2_8,md)
        end do
        ans = mod(ans + mod(mod(total_bits(i)*(n-total_bits(i)), md)*dmp, md),md)
    end do

    print*, ans

end program xor_sum4

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

int main() {
  string s;
  cin >> s;
  int a, b, c, d;
  a = s[0] - '0';
  b = s[1] - '0';
  c = s[2] - '0';
  d = s[3] - '0';

  int op[] = {-1, 1};
  char op2[] = {'-', '+'};
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        int calc = a + op[i] * b + op[j] * c + op[k] * d;
        if (calc == 7) {
          string ans;
          ans += (char)(a + '0');
          ans += op2[i];
          ans += (char)(b + '0');
          ans += op2[j];
          ans += (char)(c + '0');
          ans += op2[k];
          ans += (char)(d + '0');
          ans += "=7";
          cout << ans << endl;
          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 256
n, q = gets.split(" ").map(&:to_i)
s = gets.chomp.to_s

ary = []
q.times { ary << gets.split(" ").map(&:to_i)}

ary_num = Array.new(n, 0)
cnt = 0

(n-1).times {|i|
  cnt += 1 if s[i..i+1] == "AC"
  ary_num[i+1] = cnt
}

ary.each {|x|
  puts ary_num[x[1]-1] - ary_num[x[0]-1]
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);

    for (int tsumugi = 0; tsumugi < n; tsumugi++){
        cin >> a[tsumugi];
        b[tsumugi] = a[tsumugi];
    }

    sort(b.begin(), b.end());

    int count = 0;
    for (int matsuri = 0; matsuri < n; matsuri++){
        if (a[matsuri] != b[matsuri]){
            count++;
        }
    }
    
    if (count == 2 || count == 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256