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


#define int long long 


const int N = 303, mod = 1e9 + 7;

vector <pair <int, int> > L[N];


int n, dp[N][N][N];


int chk(int pos, int r, int g, int b) {
	for(auto z: L[pos]) {
		int c = (z.first <= r) + (z.first <= g) + (z.first <= b);
		if(c != z.second) {
			return 0;
		}
	}
	return 1;
}

int f(int r, int g, int b) {
	int pos = max({r, g, b}) + 1;
	if(pos > n) {
		return 1;
	}
	if(~dp[r][g][b]) {
		return dp[r][g][b];
	}
	int res = 0;
	if(chk(pos, pos, g, b)) {
		res += f(pos, g, b);
	}
	if(chk(pos, r, pos, b)) {
		res += f(r, pos, b);
	}
	if(chk(pos, r, g, pos)) {
		res += f(r, g, pos);
	}
	return dp[r][g][b] = res % mod;
}

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int m; cin >> n >> m;
	for(int i = 1; i <= m; i++) {
		int l, r, x; cin >> l >> r >> x;
		L[r].push_back(make_pair(l, x));
	}
	memset(dp, -1, sizeof dp);
	cout << f(0, 0, 0) << endl;
}

Measured memory_bytes: 221032
import std.conv, std.stdio;
import std.algorithm, std.array, std.range, std.string;
void main()
{
    immutable n = readln.chomp.to!size_t, s = readln.chomp;
    auto count = ['R': long(0), 'G': 0, 'B': 0];
    foreach (l; s)
        count[l] += 1;
    auto answer = count['R'] * count['G'] * count['B'];
    foreach (i; 0..s.length)
        foreach (k; i+2..s.length)
        {
            if ((i ^ k) & 1) continue;
            immutable j = (i + k) >> 1;
            if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
                answer -= 1;
        }
    answer.writeln;
}


Measured memory_bytes: 2744
input = gets.chomp.to_i
 
res = false
(2..9).each do |i|
  if input % i == 0 && input / i <= 9
      res = true 
      break
  end
end
 
if (1..9).include?(input) || res 
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define par pair<int,int>
using namespace std;
const int N=305,MOD=1e9+7;
int f[N][N][N],n,m,ans;
vector<par>e[N];
int inc(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
int main(){
    scanf("%d%d",&n,&m);
	while(m--){
		int l,r,x;scanf("%d%d%d",&l,&r,&x);
		e[r].push_back(par(l,x));
	}
	f[1][0][0]=3;
	for(int i=1;i<=n;++i)
		for(int j=0;j<i;++j)
			for(int k=j;k<i;++k){
				for(par x:e[i]){
					if(x.second==1&&k>=x.first)f[i][j][k]=0;
					if(x.second==2&&(k<x.first||j>=x.first))f[i][j][k]=0;
					if(x.second==3&&j<x.first)f[i][j][k]=0;
				}
				if(i==n)inc(ans,f[i][j][k]);
				inc(f[i+1][j][k],f[i][j][k]);
				inc(f[i+1][j][i],f[i][j][k]);
				inc(f[i+1][k][i],f[i][j][k]);
			}
	printf("%d\n",ans);
}


Measured memory_bytes: 108800
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, char> plc;

vector<int> p;

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

	p.resize(n+1);

	FOR(i,1,n+1) cin >> p[i];

	int ans = 0;
	for (int i = 1; i <= n-1; i++) {
		if ((p[i] == i )&& (p[i + 1] == i + 1)) {
			swap(p[i], p[i + 1]);
			ans++;
		}
	}

	for (int i = 1; i <= n - 1; i++) {
		if ((p[i] == i) || (p[i + 1] == i + 1)) {
			swap(p[i], p[i + 1]);
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


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

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

const MOD: i64 = 1_000_000_007;

fn main() {
    let mut n: usize = read();
    let mut ans: i64 = 1;
    let mut cnt: i64 = 1;

    while n > 0 {
        ans *= cnt;
        ans %= MOD;
        cnt += 1;
        n -= 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
string n;
cin>>n;
ll ca=0;
for(ll i=0; i<=5; i++){
if(n.at(i)=='1'){
ca++;}}
cout <<ca<< endl;
return 0;}



Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
map <long long,int>fr;
long long a,b,x,i,j,lg;

int verif(long long x)
{
    if(x<=2)
        return 1;
    long long d=3;
    if(x%2==0)
        return 0;
    while(d*d<=x)
    {
        if(x%d==0)
            return 0;
        d+=2;
    }
    return 1;
}
int main()
{
    cin>>a>>b;
    for(i=1;i*i<=a;i++)
        if(a%i==0)
            fr[a/i]++ , fr[i]++;
    for(i=1;i*i<=b;i++)
        if(b%i==0)
        {
            if(fr[i]!=0)
                if(verif(i))
                    lg++;
            if(fr[b/i]!=0 && b/i!=i)
                if(verif(b/i))
                    lg++;
        }
    cout<<lg;
    return 0;
}


Measured memory_bytes: 640
def room(bill,f,r,v)
    case f
    when 1
        bill["#{f}"][r - 1] += v
    when 2
        bill["#{f}"][r - 1] += v
    when 3
        bill["#{f}"][r - 1] += v
    when 4
        bill["#{f}"][r - 1] += v
    end

end

def divide_bill_line
    puts "####################"
end

n = gets.chomp.to_i
bill_1 = {"1"=>Array.new(10,0), "2"=>Array.new(10,0), "3"=>Array.new(10,0), }
bill_2 = {"1"=>Array.new(10,0), "2"=>Array.new(10,0), "3"=>Array.new(10,0), }
bill_3 = {"1"=>Array.new(10,0), "2"=>Array.new(10,0), "3"=>Array.new(10,0), }
bill_4 = {"1"=>Array.new(10,0), "2"=>Array.new(10,0), "3"=>Array.new(10,0), }
n.times do |i|
    b, f, r, v = gets.chomp.split.map(&:to_i)
        case b
        when 1
            room(bill_1, f, r, v)
        when 2
            room(bill_2, f, r, v)
        when 3
            room(bill_3, f, r, v)
        when 4
            room(bill_4, f, r, v)
        end
end
4.times do |i|
    case i
    when 0
        bill_1.values.each do |a|
            a.each do |c|
                #if c == 9
                #    print "#{c}"
                #else
                    print " #{c}"
                #end
            end
            puts ""
        end
        divide_bill_line
    when 1
        bill_2.values.each do |a|
            a.each do |c|
                #if c == 0
                #    print "#{c}"
                #else
                    print " #{c}"
                #end
            end
            puts ""
        end
        divide_bill_line
    when 2
        bill_3.values.each do |a|
            a.each do |c|
                #if c == 0
                #    print "#{c}"
                #else
                    print " #{c}"
                #end
            end
            puts ""
        end
        divide_bill_line
    when 3
        bill_4.values.each do |a|
            a.each do |c|
                #if c == 0
                #    print "#{c}"
                #else
                    print " #{c}"
                #end
            end
            puts ""
        end
    end
end

Measured memory_bytes: 8812
n = gets.chomp.to_i

v = gets.chomp.split(" ").map(&:to_i)

v1 = Hash.new(0)
v2 = Hash.new(0)

n.times do |i|
  if i.odd?
    v1[v[i]] += 1
  else
    v2[v[i]] += 1
  end
end

k1 = v1.sort{|a, b| a[1] <=> b[1]}.reverse
k2 = v2.sort{|a, b| a[1] <=> b[1]}.reverse

if k1[0][0] == k2[0][0]
  if k1.length == 1 && k2.length == 1
    puts n/2
  elsif k1.length == 1
    puts [n - k1[0][1] - k2[1][1], n - n/2 - k2[0][1]].min
  elsif k2.length == 1
    puts [n - k1[0][1] - n/2, n - k1[1][1] - k2[0][1]].min
  else
    puts [n - k1[0][1] - k2[1][1], n - k1[1][1] - k2[0][1]].min
  end
else
  puts n - k1[0][1] - k2[0][1]
end


Measured memory_bytes: 21316
n = int(input())
v = list(map(int, input().split()))

O = {}
E = {}

for i in v[0::2]:
    if i in O:
        O[i] += 1
    else:
        O[i] = 1

for i in v[1::2]:
    if i in E:
        E[i] += 1
    else:
        E[i] = 1

o_candidate = [[0, 0], [0, 0]]
e_candidate = [[0, 0], [0, 0]]

for i, j in O.items():
    if j >= o_candidate[0][1]:
        o_candidate[1] = o_candidate[0]
        o_candidate[0] = [i, j]
    elif j >= o_candidate[1][1]:
        o_candidate[1] = [i, j]

for i, j in E.items():
    if j > e_candidate[0][1]:
        e_candidate[1] = e_candidate[0]
        e_candidate[0] = [i, j]
    elif j >= o_candidate[1][1]:
        o_candidate[1] = [i, j]

if o_candidate[0][0] != e_candidate[0][0]:
    ans = n - o_candidate[0][1] - e_candidate[0][1]
else:
    ans = min(n - o_candidate[0][1] - e_candidate[1][1],
              n - o_candidate[1][1] - e_candidate[0][1])

print(ans)


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

int main() {
  
  int N,M;
  cin >> N >> M;
  
  vector<int> ab(M*2);
  for(int i=0; i<M*2; i++){
    cin >> ab.at(i);
  }
  
  for(int j=1; j<N+1; j++){
    int k=0;
    for(int i=0; i<M*2; i++){
      if(ab.at(i)==j){
        k++;
      }
    }
    cout << k << endl;
  }
}

Measured memory_bytes: 256
X,Y,A,B,C = map(int,(input().split()))
p = list(map(int,(input().split())))
q = list(map(int,(input().split())))
r = list(map(int,(input().split())))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

P = [0]*(A+1)
P[1] = p[0]
for i in range(2,A+1):
    P[i] = P[i-1] + p[i-1]

Q = [0]*(B+1)
Q[1] = q[0]
for i in range(2,B+1):
    Q[i] = Q[i-1] + q[i-1]

R = [0]*(C+1)
R[1] = r[0]
for i in range(2,C+1):
    R[i] = R[i-1] + r[i-1]

z = 0
res = []
#print(P,Q,R)
x = X
y = Y
p.append(10000000000)
q.append(10000000000)

for i in range(C+1):
    #print(x,y,z)
    hp = P[x] + Q[y] + R[z]
    if p[x-1] <= q[y-1] and x > 0:
        x -= 1
        z += 1
    elif p[x-1] >= q[y-1] and y > 0:
        y -= 1
        z += 1

    res.append(hp)
#print(res)
print(max(res))

Measured memory_bytes: 111204
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    char s[5];
    cin >> s;
    
    cout << 0+count(s,s+4,'+')-count(s,s+4,'-');
}

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

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  if (tail + 1 == LEN){
    tail = 0;
  }else{
    tail++;
  }
}

P dequeue(){
  P x = Q[head];
  if (head + 1 == LEN){
    head = 0;
  }else{
    head++;
  }
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
    tail=i;
    u.t = 0;
    while (head!=tail){
        if (Q[head].t > q){ 
            Q[head].t -= q; 
            u.t += q;
            enqueue(dequeue());
        }
        else if (Q[head].t <= q){
            u.t += Q[head].t;
            strcpy(u.name, Q[head].name);
            dequeue();
            printf("%s %d\n",u.name,u.t);
        }
    }
  
  return 0;
}

Measured memory_bytes: 10768
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) {
		int i,j, k;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		sc.close();
		boolean f = false;
LABEL:	for (i = 0; i <= 25; i++) {
			for (j = 0; j < 14; j++) {
				if(n==4*i+7*j) {
					f = true;
					break LABEL;
				}
			}
		}
		out.println(f?"Yes":"No");
	}
}


Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#define REP(i,n) for(int i = 0; i < n; i++)
#define REP(j,n) for(int j = 0; j < n; j++)

using namespace std;
typedef pair<int, int> P;
int lis[100000];
int tim[100000];
int main() {
    int n,r,l;
    scanf("%d %d %d",&n,&r,&l);

    int top = 0;
    int id  = 1;
    int nowtime = 0;
    int timemax = 0;
    int timemaxid = 0;
    for(int i = 0; i < r; i++) {
       
        int d,t,x;
        scanf("%d %d %d",&d,&t,&x);
        tim[id] += t - nowtime;
        if(tim[id] > timemax) {
            timemax = tim[id];
            timemaxid = id;
        }
        nowtime = t;
        lis[d] += x;
        if(id == d) {
            top += x;
        }
        if(x < 0 && d == id) {
            for(int j = 1; j < n+1; j++) {
                if(top < lis[j] || (top == lis[j] && j < id)) {
                    top = lis[j];
                    id = j;
                }
            }
            
        }
        if(x > 0 && d != id) {
            if(top < lis[d] || (top == lis[d] && d < id)) {
                top = lis[d];
                id = d;
            }
        }

    }
    tim[id] += l - nowtime;
    if(tim[id] > timemax) {
        timemax = tim[id];
        timemaxid = id;
    }
    printf("%d\n",timemaxid);
}

Measured memory_bytes: 1964
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int n = Integer.parseInt(br.readLine());
        
        for(int i = 0; i < n; i++) {
            String[] tmpArray = br.readLine().split(" ");
            Point2D[] points = new Point2D[4];
            
            for(int j = 0; j < 4; j++) {
                int x = Integer.parseInt(tmpArray[j * 2]);
                int y = Integer.parseInt(tmpArray[j * 2 + 1]);
                
                points[j] = new Point2D.Double(x, y);
            }
            
            Line2D[] lines = new Line2D[2];
            
            for(int j = 0; j < 2; j++) {
                lines[j] = new Line2D.Double(points[j * 2], points[j * 2 + 1]);
            }
            
            Point2D result = crossPoint(lines[0], lines[1]);
            
            System.out.printf("%.8f %.8f\n", result.getX(), result.getY());
        }
    }
    static Point2D crossPoint(Line2D line1, Line2D line2) {
        if(!line1.intersectsLine(line2)) return null;
        
        if(line1.getX1() == line1.getX2()) {
            double a = (line2.getY2() - line2.getY1()) / (line2.getX2() - line2.getX1());
            
            return new Point2D.Double(line1.getX1(), a * (line1.getX1() - line2.getX1()) + line2.getY1());
        }
        else if(line2.getX1() == line2.getX2()) {
            double a = (line1.getY2() - line1.getY1()) / (line1.getX2() - line1.getX1());
            
            return new Point2D.Double(line2.getX1(), a * (line2.getX1() - line1.getX1()) + line1.getY1());
        }
        else {
            double a1 = (line1.getY2() - line1.getY1()) / (line1.getX2() - line1.getX1());
            double a2 = (line2.getY2() - line2.getY1()) / (line2.getX2() - line2.getX1());
            double b1 = -a1 * line1.getX1() + line1.getY1();
            double b2 = -a2 * line2.getX1() + line2.getY1();
            
            double x = (b2 - b1) / (a1 - a2);
            double y = a1 * x + b1;
            
            return new Point2D.Double(x, y);
        }
    }
}


Measured memory_bytes: 34872
# -*- coding: utf-8 -*-

R,C,K = map(int, input().split())

items = [[0 for _ in range(C+1)] for _ in range(R+1)]
for i in range(K):
  r,c,v = map(int, input().split())
  items[r][c] = v

DP_prev = [0 for _ in range(C+1)]

for r in range(1,R+1):
  DP = [[0 for _ in range(C+1)],[0 for _ in range(C+1)],[0 for _ in range(C+1)]]
  for c in range(1,C+1):
    item = items[r][c]
    DP1 = max(DP_prev[c]+item,DP[0][c-1])
    DP2 = max(DP1,DP[1][c-1],DP[0][c-1]+item)
    DP3 = max(DP2,DP[2][c-1],DP[1][c-1]+item)
    DP[0][c] = DP1
    DP[1][c] = DP2
    DP[2][c] = DP3
  DP_prev = DP[2]
        
print(DP_prev[C])

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

int main(){
  int a, b, n;
  int suma = 0;
  int sumb = 0;
  while(1){
    cin >> n;
    if(n == 0) break;
    for(int i = 0; i < n; i++){
      cin >> a >> b;
      if(a > b) suma += a + b;
      else if(a < b) sumb += a + b;
      else if(a == b){
        suma += a;
        sumb += b;
      }
    }
    cout << suma << " " << sumb << endl;
    suma = 0;
    sumb = 0;
  }
  return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int A, B;
    cin >> A >> B;

    bool f = false;
    FOR(c, 1, 4) {
        if (A * B * c % 2) f = true;
    }

    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri register int
const long double PI=3.141592653589793238462643383279;
const int N=500005,M=998244353;
int n,i,s[N],d;
long long ans;
long long qpow(long long a,long long b)
{
	long long s=a,ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*s%M;
		s=s*s%M;
		b>>=1;
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	printf("%d",(n-1)/2);
}


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

bool binarySearch(int A[], int key, int n) {
    int left = 0, right = n;
    while (left < right) {
        int mid = (left + right) / 2;
        if (A[mid] == key) {
            return true;
        } else if (key < A[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return false;
}

int main() {
    int n, q;
    int S[100100], T[50010];
    int cnt = 0;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> S[i];
    }
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> T[i];
    }

    for (int i = 0; i < q; ++i) {
        int key = T[i];
        if(binarySearch(S, key, n)) cnt++;
    }

    cout << cnt << endl;

    return 0;

}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

#define BUY 0
#define SELL 1

int main() {
    ll N; cin >> N;
    vector<int> A(N); for (int i = 0; i < N; ++i) cin >> A[i];
    int i = 1;
    bool action = BUY;
    ll money = 1000;
    ll stock = 0;
    while (i < N) {
        if (action == BUY) {
            if (A[i] <= A[i - 1]) {
                i++;
                continue;
            }
            else {
                // cout << "BUY " << i - 1 << endl;
                // cout << A[i - 1] << " " << A[i] << endl;
                // 買ったことにする
                ll poss_stock = floor((double)money / A[i - 1]);
                money -= poss_stock * A[i - 1];
                stock += poss_stock;
                action = SELL;
                // cout << "Money " << money << " stock " << stock << endl;
                // cout << endl;
            }
        }
        else {
            if (A[i - 1] <= A[i]) {
                i++;
                continue;
            }
            else {
                // cout << "SELL" << endl;
                // cout << A[i - 1] << " " << A[i] << endl;
                money += A[i - 1] * stock;
                stock = 0;
                action = BUY;
                // cout << "Money " << money << " stock " << stock << endl;
                // cout << endl;
            }
        }
    }
    if (action == SELL) {
        money += stock * A[N - 1];
    }

    if (money < 1000) {
        cout << 1000 << endl;
    }
    else {
        cout << money << endl;
    }
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b;
    string s,t,u;
    cin>>s>>t>>a>>b>>u;
    if(u==s)
        a--;
    else
        b--;
    cout<<a<<" "<<b<<endl;

    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import numpy as np

N,M = map(int,stdin.readline().strip().split())

A = np.zeros((N,M))

for i in range(N):
    inp = list(map(int,stdin.readline().strip().split()))
    for j in range(inp[0]):
        A[i,inp[j+1]-1] = 1

B = np.sum(A,axis=0)
print(np.count_nonzero(B==N))
 


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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int N;
  cin >> N;
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    for (int j = -1; j < 2; j++) {
      mp[a + j]++;
    }
  }
  int ans = 0;
  for (auto x : mp) {
    ans = max(ans, x.second);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4736
N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]

counter = {}
for s in S:
    if s in counter:
        counter[s] += 1
    else:
        counter[s] = 0

    
ans = 0
for v in counter.values():
    for i in range(1, v + 1):
        ans += i
print(ans)


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

int main(){
	int n;
	int p[20010];
	scanf("%d",&n);
	for(int i = 0 ; i < n ; i ++){
		scanf("%d",&p[i]);
	}
	
	int a[20010],b[20010];
	for(int i = 1 ; i <= n ; i ++){
		a[i] = i;
		b[i] = n+1-i;
	}
	for(int i = 0 ; i < n ; i ++){
		for(int j = p[i]+1 ; j <= n ; j ++){
			a[j] += n-i;
		}
		for(int j = 1 ; j <= p[i]-1 ; j ++){
			b[j] += n-i;
		}
	}
	for(int i = 1 ; i <= n ; i ++){
		printf("%d%c",a[i],(i==n)?'\n':' ');
	}
	for(int i = 1 ; i <= n ; i ++){
		printf("%d%c",b[i],(i==n)?'\n':' ');
	}
}



Measured memory_bytes: 896
#!/usr/bin/env python3

N = int(input().split()[0])
w_list = []
is_ok = True
for i in range(N):
    w = input()

    if w in w_list:
        is_ok = False
        break

    w_list.append(w)
    if i == 0:
        tail = w[-1]
        continue

    if w[0] != tail:
        is_ok = False
        break
    tail = w[-1]


ans = "Yes" if is_ok else "No"
print(ans)


Measured memory_bytes: 3060
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const ll inf = 1e12 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
int a[N], b[N];
int n, m;
ll pre[N];

int f(int x, int y) {
  return y-x < 0 ? y-x+m : y-x;
}

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", a+i);
  ll ans = 0;
  for (int j = 2; j <= n; j++) {
    int l = a[j-1], r = a[j];
    if (r < l)
      r += m;
    if (r - l > 1) {
      pre[l+2] += 1;
      pre[r+1] -= 1;
      pre[r+1] -= r - l - 1;
      pre[r+2] += r - l - 1;
    }
    ans += r - l;
  }
  ll mx = 0;
  for (int i = 1; i <= 2 * m; i++)
    pre[i] += pre[i-1];
  for (int i = 1; i <= 2 * m; i++)
    pre[i] += pre[i-1];
  for (int i = 1; i <= m; i++)
    mx = max(mx, pre[i] + pre[i+m]);
  printf("%lld\n", ans - mx);
  return 0;
}


Measured memory_bytes: 5888
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>


using namespace std;
typedef long long li;


// Index range: [1, n]
// sum(x) returns the sum over [1, x]
// add(x, v) adds v to the value at x.
template <class T>
struct BIT {
    int n;
    vector<T> bit;

    BIT(int _n): n(_n), bit(_n + 1) {}

    T sum(int i) {
        T s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, T x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }
};

template <class T>
struct RangeAddBIT {
    BIT<T> bit;
    // index: [1, n]
    RangeAddBIT(int n): bit(n + 1) {}

    void range_add(int l, int r, T v) {
        // add v to [l, r]
        if (r < l) {
            return;
        }
        bit.add(l, v);
        bit.add(r + 1, -v);
    }

    T get_at(int i) {
        return bit.sum(i);
    }
};

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

    li n, m;
    cin >> n >> m;
    vector<vector<pair<li, li>>> ranges(m + 1);
    for (int i = 0; i < n; ++i) {
        li l, r;
        cin >> l >> r;
        ranges[r - l + 1].emplace_back(l, r);
    }

    RangeAddBIT<li> rab(m);
    li longer = n;
    for (int d = 1; d <= m; ++d) {
        li ans = longer;
        for (int p = d; p <= m; p += d) {
            ans += rab.get_at(p);
        }
        cout << ans << endl;

        for (auto && range: ranges[d]) {
            rab.range_add(range.first, range.second, 1);
            longer--;
        }
    }


    return 0;
}


Measured memory_bytes: 11136
import numpy as np
n,d=map(int,input().split())
L=[]
ans=0
for i in range(n):
    A=list(map(int,input().split()))
    L.append(A)
P=np.array(L)
for i in range(n):
    for j in range(i,n):
        if np.linalg.norm(P[i]-P[j])>0 and np.linalg.norm(P[i] - P[j])%1==0:
            ans+=1
print(ans)

Measured memory_bytes: 13208
import sys
sys.setrecursionlimit(10**6)

a = input() + "$"
n = len(a)

alph = "abcdefghijklmnopqrstuvwxyz"
dp = [-1] * (n + 1)

next_ = [[-1] * (n + 1) for i in range(26)]
for char in range(26):
    tmp = - 1
    for i in range(n)[::-1]:
        if a[i] == alph[char]:
            tmp = i + 1
        next_[char][i] = tmp


def solve():
    for i in range(n + 1)[::-1]:
        tmp = n + 1
        for char in range(26):
            if next_[char][i] == -1:
                dp[i] = 1
                break
            tmp = min(dp[next_[char][i]] + 1 , tmp)
        else:
            dp[i] = tmp

solve()
ans = []
i = 0
while True:
    for char in range(26):
        if next_[char][i] == -1:
            ans.append(alph[char])
            print("".join(ans))
            exit()
        if dp[i] == dp[next_[char][i]] + 1:
            ans.append(alph[char])
            i = next_[char][i]
            break

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector< ii >
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

int gcd(int a, int b){
  if(a == 0 || b == 0) return 0;
  else return abs(__gcd(a,b));
}

int32_t main(){
  DESYNC;
  int n;
  cin >> n;
  int dp[n+1][3];
  for(int i=0; i<=n; i++){
    dp[i][0] = dp[i][1] = dp[i][2] = INF;
  }
  dp[0][0] = dp[0][1] = dp[0][2] = 0;
  for(int i=1; i<=n; i++){
    int a,b,c;
    cin >> a >> b >> c;
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a;
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b;
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c;
  }
  cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}



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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define ZERO(a) memset(a,0,sizeof(a))

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin>>n;
  ll a[n][n];
  REP(i,n)REP(j,n)cin>>a[i][j];

  vll dp((1<<n),0);

  dp[0] = 1;
  REP(bit, (1<<n)){
    ll bit_count=0;
    REP(i,n){
      if((bit>>i)&1)
        bit_count++;
    }
    if(bit_count==0)
      continue;

    REP(i,n){
      if((bit>>i)&1 && a[bit_count-1][i]==1)
        dp[bit]=(dp[bit] + dp[bit^(1<<i)])%MOD;
    }
  }

  ll ans = dp[(1<<n)-1];
  cout<<ans<<endl;
}



Measured memory_bytes: 16640
//
// Created by 中野誠大 on 2019-02-10.
//

#include<iostream>

#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;


int main() {
    int N;
    cin >> N;
    int ans = 1;
    while (2*ans <= N) ans*=2;

    cout << ans <<endl;
}



Measured memory_bytes: 256
// Author: Amey Bhavsar
// IDE: Geany/Ubuntu
// Platform: MarathonForces #1

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

typedef long long ll;

#define rep(i,a,b) for(auto i=a;i<b;i++)
#define repD(i,a,b) for(auto i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
// traversal function to avoid long template definition
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)
//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())
// ll fe (ll x, ll y) {
	// ll ans = 1;
	// while (y>0) {
		// if (y&1) {
			// ans = (x*ans) % MOD;
		// }
		// y /= 2;
		// x = (x*x) % MOD;
	// }
	// return (ans % MOD);
// }

// ll modmul(ll a, ll b) {
    // return ((a%MOD) * (b%MOD)) % MOD;
// }

// ll modadd(ll a , ll b){
    // return((a%MOD)+(b%MOD)+MOD)%MOD;
// }

// ll modsub(ll a , ll b){
    // return((a%MOD) - (b%MOD) + MOD)%MOD;
// }
#define MOD 1000000007

int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int n,x;
	cin >> n >> x;
	vector<int> l(n); for(auto& e:l) cin >> e;
	vector< int > cc = {0};
	int ans = 1;
	rep(i,0,n) {
		cc.pb(cc[i]+l[i]);
		if (cc.back() > x) break;
		ans++;
	}
	cout << ans;
	
	
	
	return 0;
}


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

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int main()
{
    int N;
    cin >> N;
    vi A(N), B(N);
    for (int i = 0; i < N; i++)
        cin >> A[i] >> B[i];

    sort(begin(A), end(A), less<int>());
    sort(begin(B), end(B), greater<int>());

    ll ans;
    int hN = N / 2;
    if (N % 2 == 0)
    {
        ll kagen0 = A[hN-1];
        ll kagen1 = A[hN];
        ll jogen0 = B[hN-1];
        ll jogen1 = B[hN];
        ans = (jogen0 + jogen1) - (kagen0 + kagen1) + 1;
    }
    else
    {
        int jogen = B[hN];
        int kagen = A[hN];
        ans = jogen - kagen + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=103;
int n,p[N];
ll solve(int num)
{
  ll res=0;
  for(int i=2;i<=n;i++) if(p[i]>=num) res++;
  return res;
}
int main()
{
  cin>>n;
  for(int i=2;i<=n;i++)
  {
    int cur=i;
    for(int j=2;j*j<=cur;j++) while(cur%j==0) cur/=j,p[j]++;
    if(cur>1) p[cur]++;
  }
  cout<<solve(74)+solve(24)*(solve(2)-1)+solve(14)*(solve(4)-1)+solve(4)*(solve(4 )-1)/2*(solve(2)-2)<<endl;
  return 0;
}


Measured memory_bytes: 256
x, k, d = [int(z) for z in input().strip().split()]
if k * d < 0:
    print(y)
step = int(abs(x) / d)
# print(step)
if step > k:
    if x > 0:
        print(abs(x - k * d))
    else:
        print(abs(x + k * d))
else:
    if step % 2 == k % 2:
        if x > 0:
            print(abs(x - step * d))
        else:
            print(abs(x + step * d))
    else:
        if x > 0:
            print(abs(x - step * d - d))
        else:
            print(abs(x + step * d + d))

Measured memory_bytes: 9108
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  string s; readV(s);
  writeln(s.count('1'));
}


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

int main() {
  int N;
  string S;
  cin >> N >> S ;
  int sum=1;
  
  for(int i=1;i<S.size();i++){
    if (S.at(i-1)!=S.at(i)){
      sum+=1;
    }
  }
 
  cout << sum <<endl;
}
 



Measured memory_bytes: 512
a,b=map(int,input().split())
t=b/1000
List=[-1,-1,-1]
for l in range(a+1):
    if (t-9*l-a)%4==0 and a-l-(t-9*l-a)/4>=0 and t-9*l-a>=0:
        s=int((t-9*l-a)/4)
        List=[l,s,a-l-s]
        break
print(*List)
        
        

Measured memory_bytes: 3060
use std::io::Read;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut res: Vec<Vec<(usize, usize)>> = vec![Vec::new(); n];
    for i in 0..n {
        let a: usize = itr.next().unwrap().parse().unwrap();
        for _ in 0..a {
            let x: usize = itr.next().unwrap().parse().unwrap();
            let y: usize = itr.next().unwrap().parse().unwrap();
            res[i].push((x - 1, y));
        }
    }

    let mut ans = 0;
    for i in 0..1 << n {
        let mut check: Vec<usize> = vec![1000; n];
        let mut ok = true;
        for j in 0..n {
            if i >> j & 1 == 1 {
                for &(x, y) in res[j].iter() {
                    if check[x] == 1000 {
                        check[x] = y;
                    } else if check[x] != y {
                        ok = false;
                    }
                }
            }
        }
        for j in 0..n {
            if i >> j & 1 == 1 {
                if check[j] == 0 {
                    ok = false;
                }
            } else {
                if check[j] == 1 {
                    ok = false;
                }
            }
        }
        if ok {
            ans = std::cmp::max(ans, (i as u32).count_ones());
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
class SegmentTree():
    def __init__(self, n, inf=float('inf')):
        self.n = 2**(n-1).bit_length()
        self.inf = inf
        self.data = [inf]*(2*self.n)

    def update(self, k, a):
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = min(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        L = l+self.n
        R = r+self.n
        ret = self.inf
        while L < R:
            if R & 1:
                R -= 1
                ret = min(ret, self.data[R-1])
            if L & 1:
                ret = min(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret


n, q = map(int, input().split())
T = SegmentTree(n, 2**31-1)

ans = []
for _ in range(q):
    c, x, y = map(int, input().split())
    if c:
        ans.append(T.query(x, y+1))
    else:
        T.update(x, y)
print("\n".join(map(str, ans)))



Measured memory_bytes: 12740
int main(int argc, const char * argv[]) {
    int K,S;
    scanf("%d",&K);
    scanf("%d",&S);
    int ans = 0;
    
    for(int x=0;x<=K;x++){ //0が最小値、Kが最大値なのでK回繰り返しを行う
        for(int y=0;y<=K;y++){
            int z = S-x-y;
            if(z>=0 && z<=K){
                ans = ans+1;
            }
        }
    }
    printf("%d\n",ans);
}

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

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

    vector<int> vec(N);

    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }

    int count = 0;

    for (int i = 0; i < N; i++) {
        if (vec.at(i) >= K) {
            count++;
        }
    }

    cout << count << endl;

}

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

void plot(int h, int w)
{
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (i == 0 || i == h-1 || j == 0 || j == w-1)
                cout << "#";
            else
                cout << ".";
        }
        cout << endl;
    }
    cout << endl;
}

int main(void)
{
    while (true) {
        int h, w;
        cin >> h >> w;
        if (h==0 || w ==0)
            break;
        plot(h, w);
    }
    return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
#define MOD 1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int A,B,C,D,E,F;
  set<int> X,Y;Y.insert(0);
  cin>>A>>B>>C>>D>>E>>F;
  int ans_a=-1,ans_b=-1;
  REP(a,0,31)REP(b,0,31)REP(c,0,101)REP(d,0,101){
    int x=100*A*a+100*B*b,y=C*c+D*d;
    if(100*y<=E*x&&x+y<=F){
      if((x+y)*ans_b<y*ans_a){
        ans_a=x+y;ans_b=y;
      }
    }
  }
  if(ans_b!=-1){
    cout<<ans_a<<" "<<ans_b<<"\n";
  }
  else{
    cout<<A*100<< " "<<0<<"\n";
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
#define ARR(...) vector<int>({__VA_ARGS__})
#define ARS(...) vector<string>({__VA_ARGS__})
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<double> base;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __SOULTCH
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

const ll MOD = 1e9+7;
string s;
int D;

ll dp[10000][100];

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> s >> D;

    dp[0][0] = 1;
    repp(i, 1, sz(s)) {
        rep(j, 10) rep(k, D) dp[i][(k+j)%D] += dp[i-1][k];
        rep(k, D) dp[i][k] %= MOD;
    }

    int ts = 0;
    ll res = 0;
    rep(i, sz(s)) {
        rep(j, s[i]-'0') res += dp[sz(s)-1-i][((-ts-j)%D+D)%D];
        ts += s[i]-'0';
        
        ts %= D;
        res %= MOD;
    }

    res -= (ts != 0);
    res = (res+MOD)%MOD;

    cout << res << endl;
}

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

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

    int r = count(s.begin(), s.end(), 'R');
    int ans = count(s.begin(), s.begin() + r, 'W');

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


Measured memory_bytes: 3736
#include<cstdio>
#include<cstring>
char s[100];
int m,n;
int a[100][100];
int b[100][100];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s);
		int len=strlen(s);
		for(int j=0;j<len;j++)
		  {
		  	if(s[j]=='.') a[i][j+1]=1;
		  	else b[i][j+1]=0;
		  }
	}
   	for(int i=1;i<=m;i++)
	{
		scanf("%s",s);
		int len=strlen(s);
		for(int j=0;j<len;j++)
		  {
		  	if(s[j]=='.') b[i][j+1]=1;
		  	else b[i][j+1]=0;
		  }
	}	
   bool flag=true;
   for(int i=1;i<=n-m+1;i++)
     for(int j=1;j<=n-m+1;j++)
     {
		flag=true;
		for(int g=1;g<=m;g++)
     	  {
     	     for(int h=1;h<=m;h++)
     	     if (a[i+g-1][j+h-1]!=b[g][h]) {flag=false; if(flag==false) break;}
     	     if(flag==false) break;
          }	 
		if(flag==true) 
		{
			printf("Yes");
			return 0;
		} 
     }
	printf("No");
	return 0;  
}

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

int main(){
  string s; cin >> s;
  int sz = s.size();
  int x,y; cin >> x >> y;

  vi d;
  int pos = 0;
  d.pb(0);
  while(pos < sz){
    if(s[pos] == 'T'){
      pos++;
      d.pb(0);
    }else{
      int tmp = 0;
      while(s[pos] == 'F'){
	pos++;
	tmp++;
      }
      d.back() += tmp;
    }
  }

  vvi dpx((d.size()+1)/2, vi(2*sz+1)), dpy(d.size()/2, vi(2*sz+1)); // 原点がsz
  dpx[0][d[0]+sz] = true;
  int i = 2;
  while(i < d.size()){
    rep(j,2*sz+1){
      if(j - d[i] >= 0)
	dpx[i/2][j] |= dpx[i/2 - 1][j - d[i]];
      if(j + d[i] <= 2*sz)
	dpx[i/2][j] |= dpx[i/2 - 1][j + d[i]];
    }
    i += 2;
  }

  if(d.size() >= 2)
    dpy[0][d[1]+sz] = dpy[0][-d[1]+sz] = true;
  i = 3;
  while(i < d.size()){
    rep(j,2*sz+1){
      if(j - d[i] >= 0)
	dpy[i/2][j] |= dpy[i/2 - 1][j - d[i]];
      if(j + d[i] <= 2*sz)
	dpy[i/2][j] |= dpy[i/2 - 1][j + d[i]];
    }
    i += 2;
  }
  dump(d,dpx,dpy);

  int f = dpx[(d.size()-1)/2][x+sz];
  if(d.size() >= 2) f &= dpy[d.size()/2 - 1][y+sz];
  else f &= (y == 0);
  if(f)
    cout << "Yes\n";
  else
    cout << "No\n";
}

Measured memory_bytes: 492544
#include <iostream>

using namespace std;

/* GCD , euclid */
int gcd(int x, int y) {
    int tmp;
    while (y) {
        tmp = x;
        x = y;
        y = tmp % y;
    }
    return x;
}

int main() {
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << '\n';
}



Measured memory_bytes: 3100
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
	int a,abcd[4];
	cin>>a;
	for(int i=3;i>=0;i--){
		abcd[i]=a%10;
		a=(a-(a%10))/10;
	}
	if(abcd[0]+abcd[1]+abcd[2]+abcd[3]==7){
		a=1;
	}
	if(abcd[0]+abcd[1]+abcd[2]-abcd[3]==7){
		a=2;
	}
	if(abcd[0]+abcd[1]-abcd[2]+abcd[3]==7){
		a=3;
	}
	if(abcd[0]-abcd[1]+abcd[2]+abcd[3]==7){
		a=4;
	}
	if(abcd[0]+abcd[1]-abcd[2]-abcd[3]==7){
		a=5;
	}
	if(abcd[0]-abcd[1]-abcd[2]+abcd[3]==7){
		a=6;
	}
	if(abcd[0]-abcd[1]+abcd[2]-abcd[3]==7){
		a=7;
	}
	if(abcd[0]-abcd[1]-abcd[2]-abcd[3]==7){
		a=8;
	}
	switch(a){
		case 1:
			cout<<abcd[0]<<"+"<<abcd[1]<<"+"<<abcd[2]<<"+"<<abcd[3]<<"=7"<<endl;
			break;
		case 2:
			cout<<abcd[0]<<"+"<<abcd[1]<<"+"<<abcd[2]<<"-"<<abcd[3]<<"=7"<<endl;
			break;
		case 3:
			cout<<abcd[0]<<"+"<<abcd[1]<<"-"<<abcd[2]<<"+"<<abcd[3]<<"=7"<<endl;
			break;
		case 4:
			cout<<abcd[0]<<"-"<<abcd[1]<<"+"<<abcd[2]<<"+"<<abcd[3]<<"=7"<<endl;
			break;
		case 5:
			cout<<abcd[0]<<"+"<<abcd[1]<<"-"<<abcd[2]<<"-"<<abcd[3]<<"=7"<<endl;
			break;
		case 6:
			cout<<abcd[0]<<"-"<<abcd[1]<<"-"<<abcd[2]<<"+"<<abcd[3]<<"=7"<<endl;
			break;
		case 7:
			cout<<abcd[0]<<"-"<<abcd[1]<<"+"<<abcd[2]<<"-"<<abcd[3]<<"=7"<<endl;
			break;
		case 8:
			cout<<abcd[0]<<"-"<<abcd[1]<<"-"<<abcd[2]<<"-"<<abcd[3]<<"=7"<<endl;
			break;
	}
}

Measured memory_bytes: 256
n,k = map(int, raw_input().split())
l=[]
for i in range(n):
	a = int(raw_input())
	l.append(a)

l.sort()
min=l[n-1]
for i in range(n-k+1):
	ini = l[k+i-1]-l[i]
	min = ini if min > ini else min
	
print min


Measured memory_bytes: 8964