akhauriyash/Code-Regression huggingface dataset:
fn main() {
    fn read_string() -> String {
        let mut input = String::new();
        let _ = std::io::stdin().read_line(&mut input);
        input.trim().to_string()
    }
    fn main() {
        let s = read_string();
        let t = read_string();
        let mut map1: Vec<usize> = vec![0; 26];
        let mut map2: Vec<usize> = vec![0; 26];
        for (i, j) in s.chars().zip(t.chars()) {
            let idx1 = (i as usize) - ('a' as usize);
            let idx2 = (j as usize) - ('a' as usize);
            if map1[idx1] == 0 && map2[idx2] == 0 {
                map1[idx1] = j as usize;
                map2[idx2] = i as usize;
            } else if map1[idx1] != j as usize || map2[idx2] != i as usize {
                println!("No");
                return;
            }
        }
        println!("Yes");
    }
    main()
}

Measured memory_bytes: 4352
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}
int main() {
    ll N;
    cin >> N;
    bool ans = false;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (N == i * j)ans = true;
        }
    }
    if (ans)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

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

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

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int h, w;
    cin >> w >> h;
    auto S = make_v(h+1, w, 0);
    auto T = make_v(h, w+1, 0);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            scanf("%d", &S[i][j]);
            T[i][j] = S[i][j];
        }
    }
    for (int i = h-1; i >= 0; --i) {
        for (int j = w-1; j >= 0; --j) {
            S[i][j] += S[i+1][j];
            T[i][j] += T[i][j+1];
        }
    }
    auto dp = make_v(h+1, w+1, -INF<int>);
    dp.back().back() = 0;
    for (int i = h; i >= 0; --i) {
        for (int j = w; j >= 0; --j) {
            if((i+j)&1){
                if(i) chmax(dp[i-1][j], -dp[i][j]+T[i-1][j]);
                if(j) chmax(dp[i][j-1], -dp[i][j]-S[i][j-1]);
            }else {
                if(i) chmax(dp[i-1][j], -dp[i][j]-T[i-1][j]);
                if(j) chmax(dp[i][j-1], -dp[i][j]+S[i][j-1]);
            }
        }
    }
    cout << abs(dp[0][0]) << "\n";
    return 0;
}


Measured memory_bytes: 14832
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, ii> iii;
typedef vector<pair<pair<int,int>,int>> viii;
typedef vector<pair<pair<ll,ll>,ll>> viiil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000
#define MOD 1000000007;

void solve() {
    int n;
    cin >> n;
    
    int k = 7;
    
    rep(i, n + 1) {
        if (k % n == 0) {
            cout << i+1 << endl;
            return;
        }
        k = ((k * 10) + 7) % n;
    }
    cout << -1 << endl;
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

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

}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

/*
テストケース全てに目を通す
テストケースが2個以下だったらなんかある
N最小のコーナーケースがないか調べる
制約をしっかりと確認する（1からNまでの順列、全て異なる値などの制約も含め）
制約のn*mとn,mを読み違えない
操作の逆順を考える
オーバーフローしないか確かめる
Codeforcesではscanfを使う
modの引き算には+modをする
エラー出力は消す
エラー出力を消せ！！！！！
数値の区切り位置を誤読しない
cout << fixed;
cout << setprecision(n) << ans;
 */

int main() {
    int n;
    cin >> n;
    int mn=mod;
    int x[n];
    rep(i,n)cin >> x[i];
    rep(i,101){
        int sum=0;
        rep(j,n){
            sum+=(x[j]-i)*(x[j]-i);
        }
        chmin(mn,sum);
    }
    cout << mn;



    
}

/*
*/



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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359

int main(void)
{
	string s;
	int m,h;

	while (true) {
		cin >> s;
		if (s == "-")	break;

		cin >> m;
		rep(i, m) {
			cin >> h;
			s = s.substr(h) + s.substr(0, h);
		}
		cout << s << endl;
	}
}



Measured memory_bytes: 3204
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

ll dp[13][1<<13][10]; //桁数, 現在のエレベーター,　前の桁 

bool solve(){
  int n;
  int low[7], up[7];
  
  scanf("%d", &n);
  if(n == 0) return false;
  
  for(int i=0;i<n;i++) scanf("%d%d", low+i, up+i);

  memset(dp, 0, sizeof(dp));

  dp[0][1][0] = 1;

  ll ans = 0;

  for(int i=0;i<n*2;i++){
    for(int j=0;j<(1<<(2*n));j++){
      for(int k=0;k<10;k++){
        if(!dp[i][j][k]) continue;
        int next[10] = {};

        for(int l=0;l<n;l++){
          //1桁目
          if((1 << (l*2)) & j){
            for(int x=max(1,low[l]);x<=min(9, up[l]);x++)
              next[x] |= 1 << (l*2+2);
            for(int x=max(1,low[l]/10);x<=min(9,up[l]/10);x++)
              next[x] |= 1 << (l*2+1);
          }
          //2桁目
          if((1 << (l*2+1)) & j){
            for(int x=max(0,(low[l]-k*10));x<=min(9, up[l]-k*10);x++)
              next[x] |= 1 << (l*2+2);
          }
        }

        for(int l=0;l<10;l++){
          dp[i+1][next[l] & ((1 << n*2) - 1)][l] += dp[i][j][k];
          if(next[l] & (1 << (n*2))) ans += dp[i][j][k];
        }
        
      }
    }
  }
  
  cout << ans << endl;
  return true;
}

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



Measured memory_bytes: 11464
#include<bits/stdc++.h>
using namespace std;
int wsq[200005];
int main()
{
    int n,t,ans=0;
	cin>>n>>t;
    for(int i=1;i<=n;i++)
    cin>>wsq[i];
    sort(wsq+1,wsq+n+1);
    reverse(wsq+1,wsq+n+1);
    for(int i=1;i<=t;i++)
    ans+=wsq[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N; cin >> N;
    vector<string> ans;
    if (N == 1) {
        ans = {"0"};
    } else if (N == 2) {
        ans = {"0", "11"};
    } else {
        for (int i = 0; i < N - 1; i++) {
            string s;
            s += '0';
            for (int k = 0; k < i; k++) s += '1';
            s += '0';
            ans.push_back(s);
        }
    }
    cout << ans.size() << '\n';
    for (auto &a : ans) cout << a << '\n';
    return 0;
}


Measured memory_bytes: 3308
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <queue>

using namespace std;

const double PI = 3.14159265358979;


int main() {

	priority_queue<int> PQ;

	string cmd;
	int key;
	while (true) {

		cin >> cmd;
		if (cmd == "insert") {
			cin >> key;
			PQ.push(key);
		}
		else if (cmd == "extract") {
			cout << PQ.top() << endl;
			PQ.pop();
		}
		else {
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 7036
#include<iostream>
#include<string.h>
using namespace std;
int main(){
	char s1[10],s2[10],s3[10];
		cin>>s1>>s2>>s3;
		s1[0]=toupper(s1[0]);
		s2[0]=toupper(s2[0]);
	    s3[0]=toupper(s3[0]);
	
	cout<<s1[0]<<s2[0]<<s3[0]<<endl;
	
	
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

struct edge{
    int u,v;
    ll cost;
};
bool comp(const edge& e1,const edge& e2){
    return e1.cost<e2.cost;
}

int n,e;
edge es[200010];

int kruskal(){
    sort(es,es+e,comp);
    UnionFind uf(n+1);
    ll res=0;
    for (int i=0;i<e;i++){
        edge e1=es[i];
        if (!uf.issame(e1.u,e1.v)){
            uf.merge(e1.u,e1.v);
            res+=e1.cost;
        }

    }
    return res;
}

int main() {
    cin>>n;
    vector<tuple<ll,ll,int>> vx,vy;
    rep(i,n){
        ll x,y;
        cin>>x>>y;
        vx.push_back(make_tuple(x,y,i));
        vy.push_back(make_tuple(y,x,i));
    }
    sort(all(vx));
    sort(all(vy));
    rep(i,n-1){
        ll x1=get<0>(vx[i]),x2=get<0>(vx[i+1]);
        int i1=get<2>(vx[i]),i2=get<2>(vx[i+1]);
        edge e1={i1,i2,abs(x1-x2)};
        es[i]=e1;
    }
    rep(i,n-1){
        ll x1=get<0>(vy[i]),x2=get<0>(vy[i+1]);
        int i1=get<2>(vy[i]),i2=get<2>(vy[i+1]);
        edge e1={i1,i2,abs(x1-x2)};
        es[i+n-1]=e1;
    }
    e=2*n-2;
    ll ans=kruskal();
    cout<<ans<<endl;

    

    return 0;
}

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

int main() {
	
	int A, B;
	int ans = 1;
	
	cin >> A >> B;

	
	while (true) {
		if (B <= 1) {
			ans = 0;
			break;
		}
		if (((A * ans) - (ans-1)) >= B) {
			break;
		} else {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var S = ReadLine();
        var N = S.Length;

        bool IsPalindrome(string s)
        {
            for (int i = 0; i < s.Length / 2; i++)
                if (s[i] != s[s.Length - 1 - i])
                    return false;
            return true;
        }

        var S1 = S.Substring(0, (N - 1) / 2);
        var S2 = S.Substring((N + 3) / 2 - 1);

        if (IsPalindrome(S) && IsPalindrome(S1) && IsPalindrome(S2))
            WriteLine("Yes");
        else
            WriteLine("No");
    }
}


Measured memory_bytes: 25656
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	int ans = 0;
	int outlet = 1;
	while(outlet < b) {
		outlet--;
		outlet += a;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3828
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  cin >> n;
  int l[n], r[n];
  for(int i=0; i<n; i++){
    cin >> l[i] >> r[i];
  }

  int ans = 0;
  
  for(int i=0; i<n; i++){
    ans = ans + r[i] - l[i] + 1;
  }

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


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class Pair
{
	public int A;
	public int B;

	public Pair(int a, int b)
	{
		A = a;
		B = b;
	}
}


public class D
{
	public static void Main()
	{
		int N = GetInt();
		var task = new List<Pair>(N);
		for(int i = 0; i < N; i++)
			task.Add(new Pair(GetInt(), GetInt()));
		task.Sort((x, y) => ((y.B - x.B != 0) ? (y.B - x.B) : (y.A - x.A)));

		int current = task[0].B - task[0].A;
		if(current < 0)
		{
			Console.WriteLine("No");
			return;
		}

		for(int i = 1; i < N; i++)
		{
			if(current > task[i].B)
				current = task[i].B;

			current -= task[i].A;
			if(current < 0)
			{
				Console.WriteLine("No");
				return;
			}
		}

		Console.WriteLine("Yes");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 25128
#include <stdio.h>

int main(void) {

  double x1,y1,x2,y2,xq,yq;

  double x,y;

  double angle1;

  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&xq,&yq)!=EOF) {

    if(x1==x2) {

      x=2*x1-xq;
      y=yq;

    }

    else if(y1==y2) {

      x=xq;
      y=2*y1-yq;

    }

    else {

      angle1=(y2-y1)/(x2-x1);
      x=(2.0*yq-2.0*y1+2.0*angle1*x1+(1.0/angle1-angle1)*xq)/(angle1+1.0/angle1);
      y=angle1*(xq+x-2*x1)+2*y1-yq;

    }

    printf("%lf %lf\n",x,y);

  }

  return 0;

}


  

Measured memory_bytes: 0
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    int n,k,ans=0;
	cin >> n;
	vector<int> v(n);
	rep(i,n){
		cin >> v[i];
	}

	std::sort(v.begin(),v.end());

	ans = v[(n/2)] - v[n/2-1];

	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <algorithm>
#include <tuple>
#include <vector>
#include <set>
using namespace std;

string S;
int K;
vector<string> bp;

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

    cin>>S>>K;
    for(int i = 0; i < S.length(); i++) {
        for(int j = i+1; j <= S.length() && j <= i + K; j++){
            bp.push_back(S.substr(i, j - i));
        }
    }
    sort(bp.begin(), bp.end());
    bp.erase(unique(bp.begin(), bp.end()), bp.end());
    cout<<bp[K-1]<<'\n';

    return 0;
}

Measured memory_bytes: 1660
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

r = inn()
print(3*r*r)


Measured memory_bytes: 3572
import java.io.*;
import java.util.*;
public class Main {
	static Scanner sc;
	static PrintWriter out;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int n,m;
		n = sc.nextInt();m = sc.nextInt();
		long ans = n*(n-1)/2 + m*(m-1)/2;
		out.println(ans);
		out.flush();
	} 
	static class Scanner{
		private BufferedReader br;
		private StringTokenizer st;
		public Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		public String next() throws IOException{
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		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[] inArr(int n) throws Exception{
			int a [] = new int[n];
			st = new StringTokenizer(br.readLine());
			for(int i=0;i<n;i++) {
				a[i] = Integer.parseInt(st.nextToken());
			}
			return a;
		}
	}
}

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

/**
 * @docs input_vector.md
 */
template <typename T>
std::vector<T> input_vector(int N){
  std::vector<T> ret(N);
  for(int i = 0; i < N; ++i) std::cin >> ret[i];
  return ret;
}

template <typename T>
std::vector<std::vector<T>> input_vector(int N, int M){
  std::vector<std::vector<T>> ret(N);
  for(int i = 0; i < N; ++i) ret[i] = input_vector<T>(M);
  return ret;
}


#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...)
#endif

namespace solver{

  template <typename T, int I = 1>
  auto to_0_indexed(T a){
    for(auto &x : a) x -= I;
    return a;
  }

  template <typename T>
  auto padding(const std::vector<T> &a, size_t d, T value){
    std::vector<T> ret(d, value);
    ret.insert(ret.end(), a.begin(), a.end());
    return ret;
  }


  
  constexpr int CONTEST = 26;
  
  struct Scoring{
    const int D;
    const std::vector<int> c;
    const std::vector<std::vector<int>> s;
    std::vector<int> t;
    std::vector<std::vector<int>> last;
    int prev;

    Scoring(int D, std::vector<int> c, std::vector<std::vector<int>> s):
      D(D), c(c), s(s){}
    
    int calc(std::vector<int> t_){
      t = t_;
      
      int ret = 0;
      last = std::vector(D + 1, std::vector<int>(CONTEST, 0));
      
      for(int i = 1; i <= D; ++i){
        ret += s[i][t[i]];
        for(int j = 0; j < CONTEST; ++j){
          last[i][j] = last[i-1][j];
        }
        last[i][t[i]] = i;

        for(int j = 0; j < CONTEST; ++j){
          ret -= c[j] * (i - last[i][j]);
        }

      }
 
      return prev = ret;
    }
    
    int diff(int d, int q){
      const int p = t[d];

      if(p == q) return prev;

      prev -= s[d][p];
      prev += s[d][q];
      
      {
        auto yesterday_last = last[d-1][p];
        auto today_last = last[d][p];
        for(int i = d; i <= D; ++i){
          if(last[i][p] != today_last) break;
          prev += c[p] * (i - today_last);
          prev -= c[p] * (i - yesterday_last);
          last[i][p] = yesterday_last;
        }
      }

      {
        auto yesterday_last = last[d-1][q];
        auto today_last = d;
        for(int i = d; i <= D; ++i){
          if(last[i][q] != yesterday_last) break;
          prev += c[q] * (i - yesterday_last);
          prev -= c[q] * (i - today_last);
          last[i][q] = today_last;
        }
      }
      
      t[d] = q;

      return prev;
    }
  };


  
  void solve(){
    int D; std::cin >> D;
    auto c = input_vector<int>(CONTEST);
    auto s = padding(input_vector<int>(D, CONTEST), 1, std::vector<int>(CONTEST));
    auto t = padding(to_0_indexed(input_vector<int>(D)), 1, 0);


    Scoring score(D, c, s);
    score.calc(t);

    int M; std::cin >> M;
    for(int i = 0; i < M; ++i){
      int d, q; std::cin >> d >> q;
      --q;

      t[d] = q;
      
      std::cout << score.diff(d, q) << "\n";
    }

  }
}

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


Measured memory_bytes: 3732
#include <iostream>
#include <string>
using namespace std;
#pragma warning (disable: 4996)

int N, A[1 << 18], C[3];
long long sum = 1;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];

	for (int i = 1; i <= N; i++) {
		long long cnt = 0, id = -1;
		if (A[i] == C[0]) { cnt++; id = 0; }
		if (A[i] == C[1]) { cnt++; id = 1; }
		if (A[i] == C[2]) { cnt++; id = 2; }
		if (id == -1) {
			cout << "0" << endl;
			return 0;
		}
		sum *= cnt; C[id]++;
		sum %= 1000000007;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;

signed main(){
    Int n;
    cin >> n;
    vector<Int> as(n);
    for(Int i=0;i<n;i++) cin >> as[i];
    vector<int> dp(n+1,-n-n);
    dp[0] = 0;
    for(Int a:as) dp[a]=dp[a-1]+1;
    Int ans = n-*max_element(dp.begin(),dp.end());
    if(ans==n) ans=-1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
L = { " ": "101",
      "'": "000000",
      ",": "000011",
      "-": "10010001",
      ".": "010001",
      "?": "000001",
      "A": "100101",
      "B": "10011010",
      "C": "0101",
      "D": "0001",
      "E": "110",
      "F": "01001",
      "G": "10011011",
      "H": "010000",
      "I": "0111",
      "J": "10011000",
      "K": "0110",
      "L": "00100",
      "M": "10011001",
      "N": "10011110",
      "O": "00101",
      "P": "111",
      "Q": "10011111",
      "R": "1000",
      "S": "00110",
      "T": "00111",
      "U": "10011100",
      "V": "10011101",
      "W": "000010",
      "X": "10010010",
      "Y": "10010011",
      "Z": "10010000" }


M = { "00000": "A",
      "00001": "B",
      "00010": "C",
      "00011": "D",
      "00100": "E",
      "00101": "F",
      "00110": "G",
      "00111": "H",
      "01000": "I",
      "01001": "J",
      "01010": "K",
      "01011": "L",
      "01100": "M",
      "01101": "N",
      "01110": "O",
      "01111": "P",
      "10000": "Q",
      "10001": "R",
      "10010": "S",
      "10011": "T",
      "10100": "U",
      "10101": "V",
      "10110": "W",
      "10111": "X",
      "11000": "Y",
      "11001": "Z",
      "11010": " ",
      "11011": ".",
      "11100": ",",
      "11101": "-",
      "11110": "'",
      "11111": "?" }



while True:
    try:
        s = input()
    except:
        break

    t = ""
    for i in s:
        t += L[i]
    t += "0" * ( (-len(t))%5 )

    o = ""
    for i in range( len(t) // 5 ):
        u = t[i*5:i*5+5]
        o += M[u]
    print(o)




Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, a[200000];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	int t = 1;
	int c = 0;
	for (int i = 0; i < N; i++) {
		if (a[i] == t) {
			c++;
			t++;
		}
	}
	if (c == 0)cout << -1 << endl;
	else cout << N - c << endl;
}

Measured memory_bytes: 1024
import math as m


def calc(N, D, X):
    d_max = m.floor(40 * m.sqrt(D))
    sqrts = [x * x for x in range(1, d_max)]
    count = 0
    for i in range(N):
        for j in range(i):
            d = 0
            for k in range(D):
                d += (X[i][k] - X[j][k]) ** 2
            if (d in sqrts):
                count += 1
    print(count)


s = input().split(' ')
N = int(s[0])
D = int(s[1])
X = [
    [int(s) for s in input().split(' ')]
    for _ in range(N)
]
calc(N, D, X)


Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll n; cin >> n;
  string ans = "";
  
  while(n != 0){
    
    ll per = n % 26;
    
    if(per != 0) ans += small[per-1];
    else ans += "z";
    
    if(n % 26 != 0) n /= 26;
    else{ n /= 26; n--; }
  }
  
  reverse(all(ans));
  
  cout << ans << endl;
  
  
}

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    a = sorted(list(map(int, input().split())))
    b = list(map(int, input().split()))
    c = sorted(list(map(int, input().split())))
    count = 0

    # See:
    # https://img.atcoder.jp/arc084/editorial.pdf
    # https://docs.python.jp/3/library/bisect.html
    # https://beta.atcoder.jp/contests/abc077/submissions/1740764
    from bisect import bisect_left
    from bisect import bisect_right

    for number in b:
        a_count = bisect_left(a, number)
        c_count = n - bisect_right(c, number)
        count += a_count * c_count

    print(count)


Measured memory_bytes: 23284
def main():
    global visited, adj, sets
    print = out.append
    ''' Cook your dish here! '''
    q = get_int()
    points = []
    res = 0
    for _ in range(q):
        pt = get_list()
        for i in points:
            res += ((pt[0]-i[0])**2+(pt[1]-i[1])**2)**(1/2)
        points.append(pt)
    print(2*res/q)


''' Coded with love at India by Satyam Kumar '''
import sys, threading, math
from collections import defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
# [main() for _ in range(int(input()))]
print(*out, sep='\n')

Measured memory_bytes: 38384
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
  int N;
  ll S;
  while(1){
    cin >> N;
    if(N==0) break;
    S=0;
    for(int i=1;i*i<N;i++)
      if(N%i==0) S+=(i+N/i);
    if(N!=1) S-=N;
    if(N==S) cout << "perfect number" << endl;
    else if(N>S) cout << "deficient number" << endl;
    else cout << "abundant number" << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
  int card[5];
  
  while(scanf("%d,%d,%d,%d,%d\n", &card[0], &card[1], &card[2], &card[3], &card[4] ) != EOF) {
    
    int isStraight = 1;
    sort(card, card + 5);
    if( card[0] == card[1]-1 || card[4] == 13 && card[0] == 1 ) isStraight ++;
    for(int i=1; i<4; i++) {
      if(card[i] + 1 == card[i+1]) isStraight ++;
    }
    
    if( isStraight == 5 ) {
      cout << "straight" << endl;
      continue;
    }

    int cdcnt[14]; fill(cdcnt, cdcnt+14, 0);
    for(int i=0; i<5; i++) {
      cdcnt[card[i]-1] ++;
    }

    int mxpair = 0;    
    for(int i=0; i<13; i++) {
      mxpair = max(mxpair, cdcnt[i]);
    }
    
    if( mxpair == 4 ) {
      cout << "four card" << endl;
    } 

    else if( mxpair == 3 ) {
      for(int i=0; i<5; i++) {
	if( cdcnt[card[i]-1] == 2 ) {
	  cout << "full house" << endl;
	  goto Fin;
	}
      }
      cout << "three card" << endl;
    }
    
    else if( mxpair == 2 ) {
      int twopaircnt = 0;
      
      for(int i=0; i<5; i++) {
	if( cdcnt[card[i]-1] == 2 ) twopaircnt ++;
      }
      if( twopaircnt == 2 ) {
	cout << "one pair" << endl;
      } else {
	cout << "two pair" << endl;
      }
    }
    
    else {
      cout << "null" << endl;
    }

  Fin:
    ;
  }
  
  
  return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll h;
    cin >> h;
    ll ans = 0;
    while (h != 0) {
        ans = ans * 2 + 1;
        h >>= 1;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 1000
void nitialize(void);
void push(int);
int pop(void);

int top;
int Stack[N];
int main(){
  int x;
  int a,b;
  char s[N];
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a = pop();
      b = pop();
      push(a+b);
    } 
    else if ( s[0] == '-' ){
      a = pop();
      b = pop();
      push(b-a);
    } 
    else if ( s[0] == '*' ){
      a = pop();
      b = pop();
      push(a*b);
    }
    else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",pop());
  return 0;
}
void nitialize(void){
  top=0;
}


void push(int x){
  if(top>N){
    printf("エラー（オーバーフロー）\n");
    exit(1);
  }else{
    Stack[++top]=x;
  }
}

int pop(void){
  if(top<0){
    printf("エラー（アンダーフロー）\n");
    exit(2);
  }else{
    top--;
    return Stack[top+1];
  }
}

Measured memory_bytes: 552
import java.io.*;
import java.util.*;



// 2011/10/19

//@0112 MILK  longÉµÈ¢Æ¾ßIII
public class Main {

	
	// C return falseÅ¨µÜ¢
	boolean main() throws IOException {

		int N = readIntArray()[0];
		if (N == 0)
			return false; /* ¨µÜ¢ */

		int[] k = new int[N];  //qÌÔ
		for(int i = 0; i < N; i++) {
			k[i] = readIntArray()[0];
		}
		
		// ¸
		Arrays.sort(k);
		
		long sum = 0;
		long t = 0;
		for(int i = 0; i < N; i++) {
			sum += t; 
			t += k[i];
		}

		// ðÌ\¦
		System.out.printf("%d\n", sum);
		
		return true; /* ³íI¹ Ö */
	}
	

//	private final static boolean DEBUG = true;  // debug
	private final static boolean DEBUG = false; // release

	public static void main(String[] args) throws IOException {

		if (DEBUG) {
			log = System.out;
			
			String inputStr = "3\n100\n100\n500\n0\n";

			reader = new BufferedReader(new StringReader(inputStr)); 

		}
		else {
			log = new PrintStream(new OutputStream() { public void write(int b) {} } ); // «ÌÄ
			reader = new BufferedReader(new InputStreamReader(System.in)); // R\[©ç
		}
		
		//int N = readIntArray()[0];

		for(int i = 0; /*i < N*/; i++) {
			boolean b = new Main().main();
			if (!b)
				break;
		}		
		
		reader.close();
	}

	
	static PrintStream log;
	static BufferedReader reader;
	

	// WüÍæè@1sªÌXy[XæØèÌ®lðÇÞ
	private static int[] readIntArray() throws IOException {
		
		String s = reader.readLine();
		String[] sp = s.split(" ");
		int[] a = new int[sp.length];
		for(int i = 0; i < sp.length; i++) {
			a[i] = Integer.parseInt(sp[i]);
		}
		return a;
	}
		
}

Measured memory_bytes: 13000
N=int(input())
S=input()

ret=0

for i in range(1000):
    pin="{:0>3}".format(i)
    
    pos=0
    begin=0
    while pos<3:
        begin=S.find(pin[pos],begin)+1
        if begin==0:
            break

        pos+=1
    else:
        ret+=1

print(ret)


Measured memory_bytes: 39280
import java.util.Scanner;

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

		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();

		int low = 0;
		int high = 0;
		for(int i = 0; i < m; i++) {
			int a = sc.nextInt();
			if(a < x) {
				low++;
			}
			else {
				high++;
			}
		}

		if(low < high) {
			System.out.println(low);
		}
		else {
			System.out.println(high);
		}
	}
}


Measured memory_bytes: 21844
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18


int main() {

	int h, w; cin >> h >> w;

	vector<string> a(h);

	for (int i = 0; i < h; i++) {
		cin >> a[i];
	}

	vector<int> cnts(26);

	for (int i = 0; i < h; i++) {
		string buf = a[i];

		for (char c : buf) {
			++cnts[c - 'a'];
		}
	}

	//奇数は1つ、4で割って2余る数がキー。
	int odd = 0;
	int r2 = 0;

	for (int i = 0; i < 26; i++) {
		if (cnts[i] % 2)odd++;
		if (cnts[i] & 2)r2++;
	}

	//両方偶数なら4のペアしか使えない。奇数個のもの、4で割って2余るものがあると
	//達成できない。
	if (h % 2 == 0 && w % 2 == 0) {
		if (odd || r2)cout << "No" << endl;else cout << "Yes" << endl;
	}
	else if (h % 2 == 0) {
		if (odd || r2 > h / 2)cout << "No" << endl;else cout << "Yes" << endl;
	}
	else if (w % 2 == 0) {
		if (odd || r2 > w / 2)cout << "No" << endl;else cout << "Yes" << endl;
	}
	else {
		if (odd != 1 || r2 > h / 2 + w / 2)cout << "No" << endl;else cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

    int n;
    cin >> n;
    int a[3*n];
    for (int i = 0; i < 3*n; i++) cin >> a[i];

    sort(a, a+3*n, greater<int>());

    ll ans = 0LL;
    for (int i = 0; i < n; i++) {
        ans += a[i*2+1];
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC061A
{
	class Program
	{
		static void Main(string[] args)
		{
			int a, b, c;

			var word = Console.ReadLine().Split(' ');

			a = int.Parse(word[0]);
			b = int.Parse(word[1]);
			c = int.Parse(word[2]);

			if (a <= c && c <= b)
			{
				Console.WriteLine("Yes");
			}

			else
			{
				Console.WriteLine("No");
			}

			Console.ReadKey();

		}
	}
}

Measured memory_bytes: 11092
use std::collections::BTreeSet;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let mut x_set = BTreeSet::new();
    let mut y_set = BTreeSet::new();
    let mut p = vec![];
    for _ in 0..n {
        let x: i64 = sc.read();
        let y: i64 = sc.read();
        let (x, y) = (x + y, x - y);
        x_set.insert(x);
        y_set.insert(y);
        p.push((x, y));
    }

    let mut ok = 0;
    let mut ng = 1 << 60;
    while ng - ok > 1 {
        let m = (ng + ok) / 2;

        let mut exists = false;
        for i in 0..n {
            let (x, y) = p[i];
            if x_set.range(..=(x - m)).next_back().is_some() {
                exists = true;
                break;
            }
            if x_set.range((x + m)..).next().is_some() {
                exists = true;
                break;
            }
            if y_set.range(..=(y - m)).next_back().is_some() {
                exists = true;
                break;
            }
            if y_set.range((y + m)..).next().is_some() {
                exists = true;
                break;
            }
        }

        if exists {
            ok = m;
        } else {
            ng = m;
        }
    }

    println!("{}", ok);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int w, h;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1,}, dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

void dfs(vector< vector<int> > &plane, int x, int y){
  plane[x][y] = 0;
  for(int i=0; i<8; i++){
    if(0 <= x+dx[i] && x+dx[i] < h && 0 <= y+dy[i] && y+dy[i] < w)
      if(plane[x + dx[i]][y + dy[i]] == 1)
        dfs(plane, x + dx[i], y + dy[i]);
  }

  return;
}

int main(){
  while(true){
    cin >> w >> h;
    if(w == 0)
      break;

    vector< vector<int> > plane(h, vector<int>(w));
    for(int i=0; i<h; i++)
      for(int j=0; j< w; j++)
        cin >> plane[i][j];

    int ans = 0;
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
        if(plane[i][j] == 1){
          dfs(plane, i, j);
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

constexpr ll MOD = 1e9 + 7ll;

inline ll pow_mod(ll a, ll b) {
    ll res = 1ll;
    for(; b; a = a * a % MOD, b /= 2)
        if(b & 1) res = (res * a) % MOD;
    return res;
}

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }
// End of template code!
int main() 
{
    buff();
    int n;
    cin >> n;
    map<pll, ll> count;
    ll add = 0, ans = 1; 
    auto norm = [&] (ll& a, ll& b) {
        if(a == 0 && b == 0) ++add;
        else if(a == 0) { b = 1; }
        else if(b == 0) { a = 1; }
        else {
            ll d = __gcd(a, b);
            a /= d; b /= d;
            if(b < 0) { a = -a; b = -b; }
        }
    };

    function<pll(ll a, ll b)> perp = [&] (ll a, ll b) {
        if(a == 0) return make_pair(1ll, 0ll);
        if(b == 0) return make_pair(0ll, 1ll);;
        ll d = __gcd(a, b);
        pll par = {-b/d, a/d};
        if(par.second < 0) par.first = -par.first, par.second = -par.second;
        return par;
    };

    rep(i, 0, n) {
        ll a, b;
        cin >> a >> b;
        norm(a, b);
        if(a != 0 || b != 0) {
            count[{a,b}]++;
        }
    }
    set<pll> blacklist;
    // agora temos que contar as inimizades
    for(const auto& g : count) {
        auto fuck = perp(g.first.first, g.first.second);
        if(blacklist.count(g.first) == 0) {
            long long choose_L = pow_mod(2ll, g.second);
            long long choose_R = pow_mod(2ll, count[perp(g.first.first, g.first.second)]);
            long long mul = (choose_L + choose_R - 1 + MOD) % MOD;
            ans = (ans * mul) % MOD;
            blacklist.insert(g.first);
            blacklist.insert(perp(g.first.first, g.first.second));
        }
    }
    // tem que tirar a vazia 
    cout << (ans + add - 1ll + MOD) % MOD << endl;

    return 0;
}



Measured memory_bytes: 53576
S = input()

count = 0

before_s = ""
for s in S:
    if before_s == "":
        before_s = s
        continue
    else:
        if before_s == s:
            if s == "1":
                before_s = "0"
            elif s == "0":
                before_s = "1"
            count += 1
        else:
            before_s = s
print(count)

Measured memory_bytes: 39536
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k ,count =0 , a , b;
  cin >> k >> a >> b;
  for(int i=a;i<=b;i++ ){
     if(i%k == 0){
      cout << "OK" <<"\n";
      count++;
       break;
    }
   }
  if(count==0)
    cout << "NG\n"; 
 return 0;
}

Measured memory_bytes: 3672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.function.Function;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());

      Function<String,double[]> lineSpliteThenArray =
        s -> Stream.of(s.split(" "))
          .mapToDouble(Double::parseDouble)
          .toArray();

      double[][] vecter =
        br.lines()
          .limit(2)
          .map( lineSpliteThenArray )
          .toArray(double[][]::new);

      double p1 =
        IntStream.range(0, n)
          .mapToDouble(i -> Math.abs(vecter[0][i] - vecter[1][i]) )
          .sum();

      double p2 = Math.sqrt(
        IntStream.range(0, n)
          .mapToDouble(i -> Math.pow( vecter[0][i] - vecter[1][i], 2))
          .sum() );

      double p3 = Math.pow(
        IntStream.range(0, n)
        .mapToDouble(i -> Math.pow( Math.abs(vecter[0][i] - vecter[1][i]), 3d))
        .sum() , 1d/3d );

      double p00 =
        IntStream.range(0, n)
          .mapToDouble(i -> Math.abs(vecter[0][i] - vecter[1][i]))
          .max()
          .getAsDouble();

      System.out.printf("%.8f\n%.8f\n%.8f\n%.8f\n", p1,p2,p3,p00);
    }
  }

}


Measured memory_bytes: 32008
#include<stdio.h>
#include<algorithm>
using namespace std;
pair<int,pair<int,int> > d[20000];
int e[20000];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)e[i]=0;
		e[0]=1;
		for(int i=0;i<b;i++){
			int p,q,r;
			scanf("%d%d%d",&p,&q,&r);
			q--;
			r--;
			d[i]=make_pair(p,make_pair(q,r));
		}std::sort(d,d+b);
		for(int i=0;i<b;i++){
			if(e[d[i].second.first])e[d[i].second.second]=1;
		}
		int ret=0;
		for(int i=0;i<a;i++)ret+=e[i];
		printf("%d\n",ret);
	}
}

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

typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
const double pi = 3.141592653589793238;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

void printV(vector<int> &v);
void printVV(vector<vector<int>> &vv);


int main() {
  string S;
  cin >> S;

  int cnt = 0;

  for(int i = 0; i < 3; i++) {
    if(S.at(i) == '1') cnt++;
  }

  cout << cnt << endl;

  return 0;
}


// ベクターの中身を全部出力
void printV(vector<int> &v) {
  cout << "  [ ";
  for(int i = 0; i < (int)v.size(); i++) {
    cout << v.at(i) << " ";
  }
  cout << "]" << endl;
}

void printVV(vector<vector<int>> &vv) {
  cout << "{" << endl;
  for(int i = 0; i < (int)vv.size(); i++) {
    cout << "  [ ";
    for(int j = 0; j < (int)vv.at(i).size(); j++) {
      cout << vv.at(i).at(j) << " ";
    }
    cout << "]," << endl;
  }
  cout << "}" << endl;
}


Measured memory_bytes: 256