akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static Scanner scanner = new Scanner(System.in);

	public static void main(String[] args) {

		ArrayList<String> list = new ArrayList<String>();

		while (true) {

			String text = input();

			if (text.equals("0")) {

				break;

			} else {

				list.add(text);

			}
		}

		for (int i = 0; i < list.size(); i++) {

			String[] arrays = list.get(i).split("");

			int sum = 0;

			for (int j = 0; j < arrays.length; j++) {

				sum += Integer.parseInt(arrays[j]);

			}

			System.out.println(sum);
			sum = 0;

		}

		close();

	}

	public static String input() {

		return scanner.nextLine();

	}

	public static void close() {

		if (scanner != null) {

			scanner.close();

		}
	}
}

Measured memory_bytes: 27220
from itertools import accumulate
import sys
input = lambda: sys.stdin.readline().rstrip()

MAX = 10 ** 5

def eratosthenes(n):
    is_prime = [1] * (n+1)
    is_prime[0] = 0
    is_prime[1] = 0

    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = 0
    return is_prime        


Q = int(input())

is_prime = eratosthenes(MAX)

a = [0] * (MAX+1)
for i in range(MAX+1):
    if is_prime[i] and is_prime[(i+1)//2]:
        a[i] = 1
s = a
s = list(accumulate(s))

for i in range(Q):
    l, r = map(int, input().split())
    print(s[r]-s[l-1])


Measured memory_bytes: 52256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  bool can=true;
  V<int> ans(n*n,0);
  V<bool> ok(n+1,false);
  priority_queue<Pi,V<Pi>,greater<Pi>> q;
  V<int> lat(n+1,0);

  rep(i,1,n+1){
    int x;cin>>x;
    x--;
    rep(j,0,i-1){
      q.push({x,i});
    }

    if(ans[x]){
      can=false;
    }else{
      ans[x]=i;
    }

    lat[i]=n-i;
  }

  rep(i,0,n*n){
    if(ans[i]){
      ok[ans[i]]=true;
      continue;
    }
    else{
      if(q.size()){
        if(q.top().fs<=i)can=false;
        ans[i]=q.top().sc;
        q.pop();
        continue;
      }else{
        rep(j,1,n+1){
          if(ok[j] && lat[j]){
            lat[j]--;
            ans[i]=j;
            goto flag;
          }
        }
      }
    }
    can=false;
    flag:;
  }
  
  if(can){
    cout<<"Yes"<<ENDL;
    rep(i,0,n*n){
      cout<<ans[i]<<' ';
    }
    cout<<ENDL;
  }else{
    cout<<"No"<<ENDL;
  }
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;using int32=int_fast32_t;using uint32=uint_fast32_t;using int64=int_fast64_t;using uint64=uint_fast64_t;using pi=pair<int32,int32>;using pll=pair<int64,int64>;using vi=vector<int32>;using vvi=vector<vector<int32>>;using vll=vector<int64>;using ll=int64;using ull=uint64;
#define all(x) x.begin(),x.end()
inline ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int X=read(), Y=read(), Z=read(), K=read();
    ll A[X], b, C[Z];
    for(auto &a:A) a=read();
    for(auto &c:C) c=read();
    priority_queue<ll> AB, ABC;
    int min_K_XY = min(K, X*Y);
    while(Y--){
        b=read();
        for(auto a:A)AB.push(a+b);
    }
    while (min_K_XY--) {
        for(auto c:C)ABC.push(AB.top() + c);
        AB.pop();
    }
    while(K--){
        printf("%lld\n", ABC.top());
        ABC.pop();
    }
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}


Measured memory_bytes: 43364
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
use std::collections::HashMap;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<usize>();
    let (n, m) = (line[0], line[1]);
    let mut hash: HashMap<usize, usize> = HashMap::new();

    for _ in 0..m{
        let line = read_as_vec::<usize>();
        let (a, b) = (line[0], line[1]);
        *hash.entry(a).or_insert(0) += 1;
        *hash.entry(b).or_insert(0) += 1;
    }

    if hash.iter().all(|(_v, freq)| *freq%2 == 0){
        println!("YES");
    }else{
        println!("NO");
    }
}


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

using str = string;
using ss = stringstream;

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

    int n;cin>>n;

    vector<int> c(26,100);

    for(int i=0;i<n;i++)
    {
        str s;cin>>s;

        vector<int> bc(26,0);
        for(int j=0;j<s.size();j++)bc[s[j]-'a']++;
        for(int j=0;j<26;j++)c[j]=min(c[j],bc[j]);
    }

    for(int i=0;i<26;i++)
    {
        for(int j=0;j<c[i];j++)cout<<(char)(i+'a');
    }

    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
struct edge{ int to, cost; };
const int INF = 1001001001;
const int MAX_V = 200005;
int V,E;
vector<edge> G[MAX_V];
int d[MAX_V];
int d2[MAX_V];

void dijkstra(int s){
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+MAX_V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        for(int i=0; i<G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int n, u, v;
    cin >> n >> u >> v;
    u--; v--;
    V = n;
    rep(i,n - 1){
        int from,to,cost;
        cin >> from >> to;
        from--; to--;
        cost = 1;
        edge e1, e2;
        e1.to = to; e1.cost = cost;
        e2.to = from; e2.cost = cost;
        G[from].push_back(e1);
        G[to].push_back(e2);
    }

    dijkstra(v);
    rep(i,MAX_V)d2[i] = d[i];
    dijkstra(u);

    int ans = 0;

    rep(i,MAX_V){
        if(d[i] < d2[i]){
            ans = max(ans, d2[i] - 1);
        }
    }

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

Measured memory_bytes: 11148
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  double a,b,c,PI=3.1415926535;
  cin >> a >> b >> c;
  printf("%.5f\n",a*b*sin(c*PI/180)/2);
  printf("%.5f\n",sqrt(a*a+b*b-2*a*b*cos(c*PI/180))+a+b);
  printf("%.5f\n",b*sin(c*PI/180));
  return 0;
}



Measured memory_bytes: 3232
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		
		for(int i = 0; i < S.length(); i++){
			int x = S.charAt(i)-'A';
			x = (x + N) % 26;
			System.out.print((char)(x + 'A'));
		}
		System.out.println();
	}
}

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

using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define ve vector
#define vi vector<int>
#define vi2 vector<vi>
#define vl vector<long long>
#define vl2 vector<vl>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    int n;
    cin >> n;
    long long a[n];
    rep(i, n) cin >> a[i];
    long long maxa = a[0], ans = 0;
    rep(i, n){
        maxa = max(maxa, a[i]);
        ans += maxa - a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 5208
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

int main(){
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i,0,n) cin >> s[i];
    sort(s.begin(),s.end());
    s.erase(unique(s.begin(),s.end()),s.end());
    cout << (ll) s.size() << endl;
    return 0;
}

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

int main() {
	int N;
	while (cin >> N) {
		if (N == 0) return 0;
		int W, H, S, T;
		cin >> W >> H;
		vector<vector<bool> > B(W, vector<bool>(H, false));
		for (int i = 0; i < N; i++) {
			int X, Y;
			cin >> X >> Y;
			X--, Y--;
			B[X][Y] = true;
		}
		cin >> S >> T;
		int MAX = 0;
		for (int P = 0; P <= W - S; P++) {
			for (int Q = 0; Q <= H - T; Q++) {
				int COUNT = 0;
				for (int i = P; i < P + S; i++) {
					for (int j = Q; j < Q + T; j++) {
						COUNT += B[i][j];
					}
				}
				MAX = max(MAX, COUNT);
			}
		}
		cout << MAX << endl;
	}
}


Measured memory_bytes: 3100
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int D =sc.nextInt();
    int S =sc.nextInt();
    int T =sc.nextInt();
    if(D<=S*T){System.out.println("Yes");}
    else{System.out.println("No");}
        }
  }

Measured memory_bytes: 35888
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  int ans = 0;
  cin >> a >> b >> c >> d;
  if (a <= b){   
    ans += a;
  }
  else {
    ans += b;
  }
  if (c <= d){   
    ans += c;
  }
  else {
    ans += d;
  }
  cout << ans << endl;
}

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

int main(){
    // 入力
    int n;
    std::cin >> n;
    std::vector<long long> A(n);
    for(int i=0; i<n; i++) std::cin >> A.at(i);
    std::sort(A.begin(),A.end());


    long long ans=0;
    // can:willの数何回足されうるか　will:次に足されるindex
    int can = 1, will = n-1;
    for(int i=0; i<n-1; i++){
        ans += A.at(will);
        can--;
        if(can == 0){
            // もし足されきったら次に大きい数へ移る
            can = 2; // 最大値以外は2回足されうる
            will--;
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 4840
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 M, N;
  cin >> M >> N;
  cout << M * (M-1) / 2 + N * (N-1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))

count = []

for i in range(n):
  count.append(0)

for i in range(m):
  a, b = list(map(int, input().split()))
  count[a - 1] += 1
  count[b - 1] += 1

for i in range(n):
  print(count[i])


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

int main(){
    string S;
    cin >> S;
    int nedan = 700;
    if(S[0]=='o') nedan+=100;
    if(S[1]=='o') nedan+=100;
    if(S[2]=='o') nedan+=100;
    cout << nedan <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);    
#define f(i,j,k)  for(int i=j;i<k;i++)
#define fr(i,j,k) for(int i<=k-1;i>=j;i--)
#define ll long long
#define ld long double

using namespace std;

int main()
{
	fio
	int TC;
	TC=1;
	//cin>>TC;
	while(TC--)
	{
		ll n,k;
		cin>>n>>k;
		if(n%k==0)
			cout<<0<<endl;
		else
			n%k>abs(k-(n%k))?cout<<(abs(k-(n%k))):cout<<n%k<<endl;

	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define N 100

int M[N][N];

int main(){
    int n,u,k,v;
  
    cin >> n;
    for(int i = 0;i < n;++i){
        cin >> u >> k;
        // 頂点を移動する
        u--;
        // 頂点の数だけ回す
        for(int j = 0;j < k;++j){
            cin >> v;
            --v;    // ずらす
            M[u][v] = 1;
        }
    }
    
    for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
            // 2個目からは空白が必要
            if(j){
                cout << " ";
            }
            cout << M[i][j];
        }
        cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3132
X,Y,N = list(map(int,input().split()))
l = []

for i in range(N):
  x,y = list(map(int,input().split()))
  l.append([x,y])
  
l.sort()

cnt = 0
ans = 0
for i in l:
  if i[0] > i[1]+cnt:
    ans = i[0]
    break
  elif i[0] == i[1]+cnt:
    cnt += 1

if ans != 0:
  print(ans-1)
else:
  print(X)

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

using namespace std;

using ll = long long int;

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

inline
int gcd(int a, int b)
{
    if (a < b) swap(a, b);
    if (b == 0){
        return a;
    }else{
        return gcd(b, a % b);
    }
}

int main()
{
    scanInt(N);
    scanVecInt(A, N);
    int result = A[0];
    REP(i, N){
        result = gcd(result, A[i]);
    }
    cout << result << endl;
}


Measured memory_bytes: 640
package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)

    cs := make([]int, 3)
    for i := 0; i < n; i++ {
        var a int
        fmt.Scan(&a)
        cs[a-1]++
    }
    a, b, c := cs[0], cs[1], cs[2]

    // dp[i][j][k] i:1つ j:2つ k:3つの皿があるときの期待値
    dp := make([][][]float64, n+1)
    for i := range dp {
        dp[i] = make([][]float64, c+b+1)
        for j := range dp[i] {
            dp[i][j] = make([]float64, c+1)
        }
    }

    fn := float64(n)
    for k := 0; k <= c; k++ {
        for j := 0; j <= c+b; j++ {
            for i := 0; i <= n; i++ {
                fi, fj, fk := float64(i), float64(j), float64(k)
                if i == 0 && j == 0 && k == 0 {
                    continue
                } else if i == 0 || j == 0 || k == 0 || i == n || j == c+b {
                    dp[i][j][k] = fn
                    if i > 0 {
                        dp[i][j][k] += fi * dp[i-1][j][k]
                    }
                    if j > 0 && i < n {
                        dp[i][j][k] += fj * dp[i+1][j-1][k]
                    }
                    if k > 0 && j < c+b {
                        dp[i][j][k] += fk * dp[i][j+1][k-1]
                    }
                    dp[i][j][k] /= (fi + fj + fk)
                } else {
                    dp[i][j][k] = (fn +
                        fi*dp[i-1][j][k] +
                        fj*dp[i+1][j-1][k] +
                        fk*dp[i][j+1][k-1]) / (fi + fj + fk)
                }
            }
        }
    }

    fmt.Println(dp[a][b][c])
}


Measured memory_bytes: 256348
<?php
/**
 * リスト更新
 */
function update($monsters)
{
    $min = min($monsters);
    $monsters = array_map(function ($x) use ($min) {
        if ($x != $min) {
            return $x % $min;
        }
        return $x;
    }, $monsters);
    return array_filter($monsters, function ($x) {
        return $x > 0;
    });
}

function main()
{
    // 入力
    fscanf(STDIN, "%d", $n);
    $str = fgets(STDIN);
    $monsters = array_map('intval', explode(' ', $str));

    while (true) {
        $monsters = update($monsters);
        if (count($monsters) == 1 || min($monsters) == max($monsters)) {
            break;
        }
    }

    // 出力
    echo min($monsters) . "\n";
}

main();


Measured memory_bytes: 23028
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, l; cin >> n >> l;
    bool f1 = l <= 0, f2 = l + n - 1 >= 0;
    if (f1) {
        if (f2) cout << (2 * l + n - 1) * n / 2 << endl;
        else cout << (2 * l + n - 2) * (n - 1) / 2 << endl;
    } else cout << (2 * l + n) * (n - 1) / 2 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod ('Z'-'A'+1)
using namespace std;
string str;

string solve(){
  string res;
  for(int i=0;i<str.size();i++){
    int cnt=0;
    while(str[i]=='+'||str[i]=='-')cnt+=(str[i]=='+')-(str[i]=='-'),i++;
    if(cnt) res+=((str[i]-'A')+cnt%mod+mod)%mod+'A';
    else res += str[i];
    if(str[i]=='?')res[res.size()-1]='A';
  }

  for(int i=0;i<res.size();i++){ 
    if(res[i]=='['){
      res[i]=']';
      int c=1,j=i+1;
      while(c){
	if(res[j]=='[')res[j]=']',c++;
	else if(res[j]==']')res[j]='[',c--;
	j++;
      }
      reverse(res.begin()+i,res.begin()+j);
      res.erase(res.begin()+j-1),res.erase(res.begin()+i);
      i--;
    }
  }
  return res;
}


int main(){
  while(1){
    cin>>str;
    if(str==".")break;
    cout <<solve()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;

// vector<vector<int>> mat(N, vector<int>(M, 0));

int main(int argc, const char *argv[])
{
    //ABC139 B

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

    int tap = 1;
    int count;
    while(true)
    {
        if(tap>=B) break;
        tap = tap -1 + A;
        count++;
    }
    
    cout<<count;
}


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

int  main(){
	int n,x,ans=0;
    cin>>n;
  	for(int i=1;i<=n;i++){
    	cin>>x;
        if(x%2!=0 && i%2!=0){
        	ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <bitset>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define FI first
#define SE second
using namespace std;
typedef long long LL;
vector < pair<int,int> > G[105];

queue < pair<int,int> > Q;
int dis[105][105], n, m, C;
bool inq[105][105];
void Spfa(int S) {
    memset(dis, 0x3f, sizeof(dis));
    dis[S][0] = 0;
    for(int i = 1; i <= n; ++i) dis[i][n] = 0;
    Q.push(make_pair(S, 0));
    pair <int,int> t;
    while(!Q.empty()) {
        t = Q.front(); Q.pop();
        inq[t.FI][t.SE] = 0;
        int u = t.FI;
        if(u == n && dis[u][t.SE] <= C) continue;
        for(int i = 0; i < (int)G[u].size(); ++i) {
            int v = G[u][i].FI, w = G[u][i].SE;
            if(dis[v][t.SE] > dis[u][t.SE] + w) {
                dis[v][t.SE] = dis[u][t.SE] + w;
                if(!inq[v][t.SE]) Q.push(make_pair(v, t.SE)),inq[v][t.SE] = 1;
            }
            if(dis[v][t.SE + 1] > dis[u][t.SE]) {
                dis[v][t.SE + 1] = dis[u][t.SE];
                if(!inq[v][t.SE + 1]) Q.push(make_pair(v, t.SE + 1)),inq[v][t.SE + 1] = 1;
            }
        }
    }
}

int main() {
    while(scanf("%d%d%d", &n, &m, &C)) {
        if(n + m + C == 0) break;
        for(int i = 0; i < n; ++i) G[i].clear();
        for(int i = 0; i < m; ++i) {
            int u, v, w;
            scanf("%d%d%d", &u, &v, &w);
            G[u].push_back(make_pair(v, w));
        }
        Spfa(1);
        for(int i = 0; i <= n; ++i) if(dis[n][i] <= C) {
            printf("%d\n", i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1304
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

bool pair_comp(const pair<int, ll>& first_p, const pair<int, ll>& second_p){
    return first_p.second < second_p.second;
}

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

    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<ll> b(n);
    rep(i, n) cin >> b[i];
    ll remain  = accumulate(all(a), 0LL) - accumulate(all(b), 0LL);
    if(remain < 0){
        cout << "-1" << endl;
        return 0;
    }

    vector<pair<int, ll>> tmp_vec(n);
    rep(i, n) tmp_vec[i] = pair<int, int>(i, a[i] - b[i]);
    sort(all(tmp_vec), pair_comp);

    ll cnt = 0;
    rep(i, n){
        int idx = tmp_vec[i].first;
        if(b[idx] < a[idx] && a[idx] - b[idx] <= remain){ remain -= a[idx] - b[idx]; b[idx] += a[idx] - b[idx]; }
        if(a[idx] != b[idx]) cnt ++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3328
// C - Vacation
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int main(){
	int N; cin>>N;
	vi a(N), b(N), c(N);
	cin>>a[0]>>b[0]>>c[0];
	for(int n=1; n<N; n++){
		cin>>a[n]>>b[n]>>c[n];
		a[n] += max(b[n-1], c[n-1]);
		b[n] += max(c[n-1], a[n-1]);
		c[n] += max(a[n-1], b[n-1]);
	}
	cout<< max({a[N-1], b[N-1], c[N-1]}) <<endl;
}

Measured memory_bytes: 1408
N=int(input())
S=input()
R,G,B=0,0,0
ans=0
for i in range(N):
    if S[i]=='R':
        R+=1
    elif S[i]=='G':
        G+=1
    else:
        B+=1
ans+=R*G*B
f,s,t=0,1,2
while t<=N-1:
    i=0
    while i+t<=N-1:
        if S[f+i]!=S[s+i] and S[f+i]!=S[t+i] and S[s+i]!=S[t+i]:
            ans-=1
        i+=1
    s+=1
    t+=2
print(ans)

Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n; cin >> n;
    vector<int> v(n),c(n),diffs(n);
    rep(i,n) cin >> v[i];
    rep(i,n) cin >> c[i];
    rep(i,n) diffs[i] = v[i] - c[i];
    sort(diffs.begin(),diffs.end(),greater<int>());
    int res = 0;
    for ( int i = 0; diffs[i] > 0;i++){
        res += diffs[i];
    }
    cout << res << endl;
}


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

int main(int argc, char *argv[]) {
	string s, acgt = "ACGT";
	int res = 0, temp = 0;
	cin >> s;
	
	for(int i = 0; i < s.length(); i++){
		bool check = false;
		for(int j = 0; j<4; j++){
			int count = 0;
			if(s[i] == acgt[j]) check = true;
		}
		
		if(check) temp++;
		else temp = 0;
		
		if (res < temp) res = temp;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem0098 : Maximum Sum Sequence II **/
int main()
{
	int table[101][101]={0};
	int sum[101][101]={0};
	int N;
	int ans=-10000*100-1;

	cin>>N;
	REP(i, 1, N+1) {
		REP(j, 1, N+1) {
			cin>>table[i][j];
		}
	}
	
	REP(i, 1, N+1) {
		REP(j, 1, N+1) {
			sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + table[i][j];
		}
	}
	
	REP(i, 1, N+1) {
		REP(j, 1, N+1) {
			REP(x, 1,i+1) {
				REP(y, 1, j+1) {
					ans = max(ans, sum[i][j]-sum[i][y-1]-sum[x-1][j]+sum[x-1][y-1]);
				}
			}
		}
	}
	
	cout << ans << endl;
}

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

int main(){
  int n;

  while( cin>>n && n ){
    n/=4;
    int sum=0;
    for( int i=0,j;i<n;i++ ){
      cin >> j; sum+=j;
    }
    cout << sum << endl;
  }


  return 0;
}

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

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

    int B[20];
    for(int i = 0; i < M; i++)
        cin >> B[i];
    
    int A[20], ans = 0;

    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++)
            cin >> A[j];
        
        int judge = 0;
        for(int j = 0; j < M; j++)
            judge += A[j] * B[j];
        judge += C;

        if(judge > 0)
            ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
function Main(input) {
    var input = input.split('\n');
    var a = input.slice(1,input.length).map((n) => {
        return parseInt(n);
    }).sort((a, b) => {
        return (a < b ? -1 : 1);
    });

    //sortするときはちゃんとparseIntする！！！

    var Filter = a.filter((x, i, self) => 
        self.indexOf(x) === i
    );
    
    /**
     * /=>{}にするときは=>{return hoge}としないとダメ
     * indexOf(要素)は重複するとき同じ値になるので
     * 配列のインデックスとは異なる。のでそれを利用
    */

    var result = Filter.length;
    console.log(result);    
    }
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
import java.util.*;
public class Main {
 
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int w=sc.nextInt();
		int h=sc.nextInt();
		long min=Integer.MAX_VALUE;
		if(w%3==0||h%3==0){
			System.out.println("0");
		}else{
			if(w%2==0&&h%2==0){
				//System.out.println(a);
				min=Math.min(c(w,h),t(w,h));
				min=Math.min(Math.min(c(h,w),t(h,w)),min);
				System.out.println(min);
			}else if((w%2!=0&&h%2==0)||(w%2==0&&h%2!=0)){
				
				min=Math.min(c(w,h),t(w,h));
				min=Math.min(Math.min(c(h,w),t(h,w)),min);
				System.out.println(min);
			}else{
				min=Math.min(c(w,h),t(w,h));
				min=Math.min(Math.min(c(h,w),t(h,w)),min);
				System.out.println(min);
			}
		}
		
	}
	public static long c(long w,long h){
		long a=h/2;
		long b=h/2+h%2;
		long min=Integer.MAX_VALUE;
		//System.out.println(w+" "+h+" "+a+" "+b);
		long d[]=new long[3];
		for(int i=1;i<=w;i++){	
			long p=i;long q=w-i;
			//System.out.println(p+q);
			d[0]=(q*a);
			d[1]=(q*b);
			d[2]=p*h;
			//System.out.println(d[0]+d[1]+d[2]);
			//System.out.println(sum1+" "+sum2+" "+sum3 );
			Arrays.sort(d);
			long sum=d[2]-d[0];
			if(sum<min){
				//System.out.println(p+" "+q+" "+(p*h)+" "+s1);
				min=(long)sum;
		
			}
			
		}
		return min;
	}
	public static long t(long w,long h){
		
		long min=Integer.MAX_VALUE;
		//System.out.println(w+" "+h+" "+a+" "+b);
		long d[]=new long[3];
		for(int i=1;i<=w;i++){	
			long p=i;long q=w-i;
			//System.out.println(p+q);
			long a=(q/2);
			long b=q-a;
			d[0]=(h*a);
			d[1]=(h*b);
			d[2]=p*h;
			//System.out.println(a+b+p);
			Arrays.sort(d);
			long sum=d[2]-d[0];
			if(sum<min){
				//System.out.println(p+" "+q+" "+(p*h)+" "+s1);
				min=(long)sum;
		
			}
			
		}
		return min;
	}
 
}



Measured memory_bytes: 24788
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<int,int> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a){
      return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

// struct thord{
//     ll a,b;
// };

// bool cmp(thord x, thord y){
//     return x.b>=y.b;
// }

int main(){
    vector<ll> c;
    ll n,h;
    cin >> n >> h;
    ll a_max=0;
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        c.push_back(b);
        a_max=max(a,a_max);
    }
    sort(c.begin(),c.end(),greater<ll>());
    ll ans=0; 
    rep(i,n){
        ll b=c[i];
        if(a_max<b&&h>0){
            ans++;
            h-=b;
        }
    }
    if(h>0)ans+=(h+a_max-1)/a_max;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mi 1000000007
int state[200005];
int dp[5000][1005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	int cost[m+1];
	for(int i=0;i<5000;i++){
		for(int j=0;j<1005;j++){
			dp[i][j]=mi;
		}
	}
	for(int i=1;i<=m;i++){
		int q;
		cin>>cost[i]>>q;
		while(q--){
			int x;
			cin>>x;
			state[i]=state[i]|(1<<(x-1));
		}
	}
	dp[0][0]=0;
	for(int i=0;i<(1<<n);i++){
		for(int j=1;j<=m;j++){
			dp[i][j]=min(dp[i][j],dp[i][j-1]);
			dp[i|state[j]][j]=min(dp[i|state[j]][j],dp[i][j-1]+cost[j]);
		}
	}
	int ans=dp[(1<<n)-1][m];
	if(ans==mi) cout<<"-1\n";
	else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 19840
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std; 

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

    
    for (auto i = x - (k - 1); i <= x + (k - 1); ++i) {
	cout << i << " ";
    }
    cout << endl;
    
    return 0;
}
 


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int M1 = sc.nextInt();
			final int D1 = sc.nextInt();
			final int M2 = sc.nextInt();
			final int D2 = sc.nextInt();
			
			if(M1 != M2) {
				System.out.println("1");
			}else {
				System.out.println("0");
			}
			
		
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 22996
package main

import "fmt"

func main() {
	// Code for A - Signboard
	var S string
	fmt.Scan(&S)

	var T string
	T = "CODEFESTIVAL2016"

	var count int
	for i := 0; i < len(S); i++ {
		if S[i] != T[i] {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 1768
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
money=0
bottle=0
for i in range(n):
    if bottle+l[i][1]<=m:
        bottle+=l[i][1]
        money+=l[i][0]*l[i][1]
    else:
        money+=l[i][0]*(m-bottle)
        break
print(money)

Measured memory_bytes: 27760
//How Many Divisors?

#include<stdio.h>

int main()
{
    int a,b,c,n,i;

    scanf("%d %d %d", &a, &b, &c); 
    for(i=a;i<=b;i++){
        if(c%i == 0){
            n++;
        }
    }
    
    printf("%d\n",n);
    return 0;
}




Measured memory_bytes: 2708
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        boolean[][] grid = new boolean[H][W];

        for (int i = 0; i < H; i++) {
            String row = sc.next();
            for (int j = 0; j < W; j++) {
                grid[i][j] = (row.charAt(j) == '#');
            }
        }

        int[][] dp = new int[H][W];
        int m = (int) 1e9 + 7;

        for (int j = 0; j < W; j++) {
            if (!grid[0][j]) {
                dp[0][j] = 1;
            } else {
                break;
            }
        }

        for (int i = 0; i < H; i++) {
            if (!grid[i][0]) {
                dp[i][0] = 1;
            } else {
                break;
            }
        }

        for (int i = 1; i < H; i++) {
            for (int j = 1; j < W; j++) {
                if (!grid[i][j]) {
                    dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % m;
                }
            }
        }

        System.out.println(dp[H - 1][W - 1]);
    }
}

Measured memory_bytes: 35116
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
 
typedef long long LL;
 
int N;
LL A,B,C,D;
LL L,R,Dis;
 
void Judge(){
	if(B>=L&&B<=R)
		puts("YES"),exit(0);
}
 
int main(){
	cin>>N>>A>>B>>C>>D; --N;
	L=A+C*N,R=A+D*N,Dis=C+D;Judge();
	for(int i=1;i<=N;++i)
		L-=Dis,R-=Dis,Judge();
	puts("NO");
	return 0;
}


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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) { cin1(x[i]); }
#define ncin2(n, x, y)      REP(i, 0, n) { cin2(x[i], y[i]); }
#define ncin3(n, x, y, z)   REP(i, 0, n) { cin3(x[i], y[i], z[i]); }
#define ncinp(n, p)         REP(i, 0, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }
#define ncin1_1(n, x)       REPE(i, 1, n) { cin1(x[i]); }
#define ncin2_1(n, x, y)    REPE(i, 1, n) { cin2(x[i], y[i]); }
#define ncin3_1(n, x, y, z) REPE(i, 1, n) { cin3(x[i], y[i], z[i]); }
#define ncinp_1(n, p)       REPE(i, 1, n) { lli p1,p2; cin >> p1 >> p2; p[i] = P(p1, p2); }

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

int main() {
    lli n;
    cin1(n);
    P a[n];
    P b[n];
    REP(i,0,n) {
        lli x, y;
        cin >> x >> y;
        a[i] = P(x,y);
    }
    REP(i,0,n) {
        lli x, y;
        cin >> x >> y;
        b[i] = P(x,y);
    }



    sort(b, b+n);
    bool is_done[n] = {false};
    lli ans = 0;
    REP(i,0,n) {
        // b[i] よりも左下にある a を探し、yが最も大きいものを選んでペアにする
        lli max_y = -1;
        lli ind = -1;
        REP(j,0,n) {
            if (is_done[j])
                continue;
            // a[j] は b[i] の左下にある？
            if (a[j].first < b[i].first && a[j].second < b[i].second) {
                if (max_y < a[j].second) {
                    max_y = a[j].second;
                    ind = j;
                }
            }
        }
        if (max_y != -1) {
            ans++;
            is_done[ind] = true;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    string s, t;
    cin >> s >> t;
    ll n = s.size();

    vvl v(26);
    rep(i, n) {
        v[s[i] - 'a'].pb(i);
    } 
    rep(i, n) {
        v[s[i] - 'a'].pb(i+n);
    }

    ll p = 0;
    ll ans = 0;
    rep(i, t.size()) {
        ll c = t[i] - 'a';
        if(v[c].size() == 0) {
            out(-1);
            re0;
        }
        p = *lower_bound(all(v[c]), p) + 1;
        if(p >= n) {
            p -= n;
            ans += n;
        }
    }
    ans += p;

    out(ans);
    re0;
}

Measured memory_bytes: 2800
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  
 string a;
  cin>>a;
  int count=0;
  auto itb=a.begin();
  auto ite=a.end()-1;
  for(int i=0;i<a.length()/2;i++){
   
  if(*itb!=*ite){
  count++;
  }
   itb++;ite--;
  }
  cout<<count;
  
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main () {
  int N, M, K;
  cin >> N >> M >> K;
  for (int i = 0; i <= N; i ++) {
    for (int j = 0; j <= M; j ++) {
      int S = N * M;
      int p = i * j;
      int q = (N - i) * (M - j);
      if (S - p - q == K) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;


int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    int state=0;
    string s0,s1;
    rep(i,q) {
        int t;
        cin >> t;
        if (t==1) state=1-state;
        else {
            int k;
            cin >> k;
            --k;
            char c;
            cin >> c; 
            if ((k+state)%2==0) s0.push_back(c);
            else s1.push_back(c);
        }
    } 
    rep(i,s1.size()) s.push_back(s1[i]);
    reverse(s.begin(),s.end());
    rep(i,s0.size()) s.push_back(s0[i]);
    if (state==0) reverse(s.begin(),s.end()); 
    cout << s << endl;
}

Measured memory_bytes: 1408
n, m = gets.split.map(&:to_i)
arr = m.times.map{gets.split.map(&:to_i)}

num = 'x' * n

arr.each do |a|
  if num[a[0] - 1] == 'x'
    num[a[0] - 1] = a[1].to_s
  elsif num[a[0] - 1] != a[1].to_s
    puts -1
    exit
  end
end

if n != 1 && num[0] == '0'
  puts -1
  exit
elsif n != 1 && num[0] == 'x'
  num[0] = '1'
elsif n == 1 && num[0] == 'x'
  num[0] = '0'
end

puts num.gsub(/x/, '0')

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

#define MAXN (110)

int n;
int x[MAXN], y[MAXN], h[MAXN];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d%d", x + i, y + i, h + i);
    }
    for (int cx = 0; cx <= 100; ++cx) {
        for (int cy = 0; cy <= 100; ++cy) {
            bool flag = true;
            int ans = 0, max = INT_MAX;
            for (int i = 1; i <= n; ++i) {
                int t = std::abs(x[i] - cx) + std::abs(y[i] - cy);
                if (h[i] == 0) {
                    max = std::min(max, t);
                } else {
                    if (ans == 0) {
                        ans = t + h[i];
                    } else if (ans != t + h[i]) {
                        flag = false;
                        break;
                    }
                }
                if (ans > max) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                printf("%d %d %d\n", cx, cy, ans);
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {

    vvl a(3, vl(3)), v(3, vl(3));
    rep(i, 3) {
        rep(j, 3) {
            cin >> a[i][j];
        }
    }

    ll n;
    cin >> n;

    rep(loop, n) {
        ll b;
        cin >> b;
        rep(i, 3) {
            rep(j, 3) {
                if(a[i][j] == b) {
                    v[i][j] = 1;
                }
            }
        }
    }

    bool ok = false;
    rep(i, 3) {
        if(v[i][0] && v[i][1] && v[i][2]) {
            ok = true;
        }
    }
    rep(j, 3) {
        if(v[0][j] && v[1][j] && v[2][j]) {
            ok = true;
        }
    }
    if(v[0][0] && v[1][1] && v[2][2]) {
        ok = true;
    }
    if(v[0][2] && v[1][1] && v[2][0]) {
        ok = true;
    }

    if(ok) {
        out("Yes");
    }
    else {
        out("No");
    }

    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=1000005;
#define M 1000000007
#define double long double
#define BINF 1000000000000000001
#define init(arr,val) memset(arr,val,sizeof(arr))
#define MAXN 150001
const int LG = 22;

#undef int
int main()
{
#define int long long int

ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
	
	int n,h,w;
	cin>>n>>h>>w;
	int c=0;
	while(n--)
	{
		int u,v;
		cin>>u>>v;
		if(u>=h && v>=w) c++;
	}

	cout<<c<<endl;

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <unordered_map> //C++11
using namespace std;

typedef long long ll;

int main() {
	int n, m;
	ll sum = 0, ans = 0;
	cin >> n >> m;
	ll work;
	for (int i = 1; i <= n; i++) {
		cin >> work;
		ans += work*(i - 1) - work*(n - i);
		ans %= 1000000007;
	}
	for (int i = 1; i <= m; i++) {
		cin >> work;
		sum += work*(i - 1) - work*(m - i);
		sum %= 1000000007;
	}
	ans *= sum;
	ans %= 1000000007;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 888