akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define N 13
#define M 1000000007
#define L 10

char s[111111];
int g[N][L];

int main()
{		
	long long d[2][N] = {1};
	int i, j, x, p0, p1;
	
	for(i = x = 0; i < N; i++, x += L){
		for(j = 0; j < L; j++){
			g[i][j] = (x + j) % N;
		}
	}
	
	scanf("%s", s);
	for(i = 0, p0 = 0, p1 = 1; s[i]; i++, p0 = !p0, p1 = !p1){
		if(s[i] != '?'){
			x = s[i] - 48;
			for(j = 0; j < N; j++){
				d[p1][g[j][x]] = d[p0][j];
			}
		}
		else{
			for(j = 0; j < N; j++) d[p1][j] = 0;
			for(x = 0; x < L; x++){
				for(j = 0; j < N; j++) d[p1][g[j][x]] += d[p0][j]; 
			}
			for(j = 0; j < N; j++) d[p1][j] %= M;
		}
	}
	printf("%lld\n", d[p0][5]);
		
				
	return 0;
}

Measured memory_bytes: 1828
def main():
    N = int(input())
    for h in range(1, 3501):
        denominator = 4*h - N
        numerator = N*h
        if denominator > 0:
            n = (numerator//denominator) + 1
            denominator = 4*h*n - N*(h+n)
            numerator = N*h*n
            if denominator > 0 and numerator % denominator == 0:
                print(h, n, numerator//denominator)
                exit()


if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		Scanner scan = new Scanner(System.in);

		int A, B, C, D;
		A = scan.nextInt();
		B = scan.nextInt();
		C = scan.nextInt();
		D = scan.nextInt();

		int trainCost = Math.min(A, B);
		int busCost = Math.min(C, D);

		System.out.println(trainCost + busCost);
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 27036
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] xArr = new int[n - 1];
        long xTotal = 0;
        long xprev = sc.nextInt();
        for (long i = 1; i < n; i++) {
            long a = sc.nextInt();
            xTotal += i * (n - i) * (a - xprev) % MOD;
            xTotal %= MOD;
            xprev = a;
        }
        long yTotal = 0;
        long yprev = sc.nextInt();
        for (long i = 1; i < m; i++) {
            long a = sc.nextInt();
            yTotal += i * (m - i) * (a - yprev) % MOD;
            yTotal %= MOD;
            yprev = a;
        }
        System.out.println(xTotal * yTotal % MOD);
    }
}

Measured memory_bytes: 64776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
inline ll read(){
	ll res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}


signed main(){
	int n=read(),k=read(),ans=0;
	for(int i=1;i<=n;i++){
		int a=read();
		if(a>=k) ans++;
	}
	cout<<ans<<endl;
}


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

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

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

    vector<int> L(N + 1), R(N + 1);
    L[0] = 0, R[N] = 0;
    for (int i = 0; i < N; i++) {
        L[i + 1] = gcd(L[i], A[i]);
    }
    for (int i = N - 1; i >= 0; i--) {
        R[i] = gcd(R[i + 1], A[i]);
    }

    int res = 0;
    for (int i = 0; i < N; i++) {
        int l = L[i];
        int r = R[i + 1];

        res = max(res, gcd(l, r));
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  int N; cin>>N;
  vector<int> vec(100001,0);
  rep(i,N)
  {
    int A; cin>>A;
    vec.at(A)++;
  }
  
  ll ans=0;
  rep(i,100001)
  {
    ans+=i*vec.at(i);
  }
  //cout<<ans<<endl;
  int Q; cin>>Q;
  rep(i,Q)
  {
    int B,C; cin>>B>>C;
    ans+=(C-B)*vec.at(B);
    cout<<ans<<endl;
    vec.at(C)+=vec.at(B);
    vec.at(B)=0;
  }
  
  
 
  return 0;
  }


Measured memory_bytes: 3780
#include <iostream>
#define G_MAX 1000
#define N 1000000007 
using namespace std;

int dp[G_MAX][G_MAX]={0};

int main(){
  int H,W,i,k;
  char c;
  cin>>H>>W;
  dp[0][0]=1;
  for(i=0;i<H;i++){
    for(k=0;k<W;k++){
      cin>>c;
      if(c=='.'){
        if(i>0){dp[i][k]+=dp[i-1][k];}
        if(k>0){dp[i][k]+=dp[i][k-1];}
      }
      dp[i][k]%=N;
    }
  }

  cout << dp[H-1][W-1]<<endl;
  return 0;
}

Measured memory_bytes: 4096
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String readStr;
    int[] numPatternCount = new int[19];
    int i, j, k, l;
    int size = 9;
    int sum;
    i:for (i = 0; i <= size; i++) {
      j:for (j = 0; j <= size; j++) {
        k:for (k = 0; k <= size; k++) {
          if (i + j + k > 18)
            continue j;
          l:for (l = 0; l <= size; l++) {
            sum = i + j + k + l;
            if (sum > 18)
              continue k;
            numPatternCount[sum]++;
          }
        }
      }
    }

    while ((readStr = reader.readLine()) != null) {
      int n = Integer.parseInt(readStr);
      System.out.println(
              n > 36 ? 0
              : numPatternCount[n > 18 ? numPatternCount.length - (n - numPatternCount.length) - 2 : n]
      );
    }
  }

}

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

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

    int count = 0;
    for (int i = 0; i <= D; i++) {
        int d1 = i % 10;
        int d10 = i / 10;

        if (d1 < 2 || d10 < 2) {
            continue;
        }

        for (int j = 0; j <= M; j++ ) {
            if (j == d1 * d10) {
                count++;
            }
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range, std.algorithm, std.array;
import std.numeric, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n,a,b;
    scan(n,a,b);
    writeln((b-a)&1 ? "Borys" : "Alice");
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

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

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

	int n;
	cin >> n;
	int A[n], B[n], C[n - 1];

	for (int i = 0; i < n; ++i) {
		cin >> A[i];
		A[i]--;
	}
	for (int i = 0; i < n; ++i)
		cin >> B[i];
	for (int i = 0; i < n - 1; ++i)
		cin >> C[i];

	int ans = B[A[0]];
	for (int i = 1; i < n; ++i) {
		ans += B[A[i]];
		if (A[i] - A[i - 1] == 1)
			ans += C[A[i - 1]];
	}
	cout << ans << '\n';
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define reps(i, s, n) for (int i = s; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

#define lpair pair<ll, ll>
#define llvecvec vector<vector<vector<ll>>>
#define INF 3000000000

ll item[3001][3001];
ll mydata[3001][3001][4];

ll getMax(ll r, ll c)
{
  ll maxv = 0;
  rep(i, 4)
  {
    maxv = max(maxv, mydata[r][c][i]);
  }

  return maxv;
}

int main()
{
  ll r,c,k;
  cin >> r >> c >> k;

  repl(i, r)
  {
    repl(j, c)
    {
      item[i][j] = 0;
      repl(k , 4)
      {
        mydata[i][j][k] = -INF;
      }
    }
  }
  
  repl(i, k)
  {
    ll a,b,c;
    cin >> a >> b >> c;
    item[a-1][b-1] = c;
  }

  repl(i, r)
  repl(j, c)
  repl(k, 4)
  {
    if(i == 0 && j == 0)
    {
      if(k == 1 && item[i][j] > 0)
      {
        mydata[i][j][k] = item[i][j];
      }
      else if(k == 0)
      {
        mydata[i][j][k] = 0;
      }
      else
      {
        mydata[i][j][k] = -INF;
      } 
    }
    else if(j == 0)
    {
      if(k == 1 && item[i][j] > 0)
      {
        mydata[i][j][k] = getMax(i-1, j) + item[i][j];
      }
      else if(k == 0)
      {
        mydata[i][j][k] = getMax(i-1, j);
      }
      else
      {
        mydata[i][j][k] = -INF;
      }
    }
    else if(i == 0)
    {
      if(k == 0)
      {
        mydata[i][j][k] = 0;
        continue;
      }

      ll tmp = -INF;
      if(mydata[i][j-1][k-1] >= 0 && item[i][j] > 0)
      {
        tmp = mydata[i][j-1][k-1] + item[i][j];
      }
      
      mydata[i][j][k] = max(mydata[i][j-1][k], tmp);
    }
    else
    {
      ll tmp = -INF;
      if(k > 0 && mydata[i][j-1][k-1] >= 0 && item[i][j] > 0)
      {
        tmp = mydata[i][j-1][k-1] + item[i][j];
      }
      tmp = max(tmp, mydata[i][j-1][k]);
      if(k == 1 && item[i][j] > 0)
      {
        tmp = max(tmp, getMax(i-1, j) + item[i][j]);
      }
      else if(k == 0)
      {
        tmp = max(tmp, getMax(i-1, j));
      }
      mydata[i][j][k] = tmp;
    }
  }

  cout << fixed << getMax(r-1, c-1) << endl;

  return 0;
}

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

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f
#define show(x) cerr<<#x<<" : "<<x<<'\n';
#define yogeshk972() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();
 
using namespace __gnu_pbds;
using namespace std;
const int N=2e5+1, mod=998244353;

typedef tree< int,null_type, less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>  os;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,m;	string s;
	cin>>n>>m>>s;
	vector<int> res, nxt(n+1,n);
	
	for(int i=0;i<=n;){
		if(s[i]=='0'){
			i++;
			continue;
		}
		int ct=0,j=i;
		while(s[j]=='1'){
			j++; ct++;
		}
		
		for(int j=i;j<i+ct;j++)nxt[j]=i+ct;
		i+=ct;
		if(ct>=m){
			cout<<"-1";
			return 0;
		}
	}
	
	int i=n;
	while(i!=0){ 
		int j=i;
		i=max(i-m,0);
		if(s[i]=='1'){

			i=nxt[i];
		}
		res.pb(j-i);
	}
	
	reverse(res.begin(),res.end());
	for(auto x:res)cout<<x<<" ";
	
	
	
    yogeshk972();
}


Measured memory_bytes: 1480
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdio>

using namespace std;

int main() {
	int m, f, r;
	while (true) {
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) break;

		if (m != -1 && f != -1) {
			if (m + f >= 80) cout << "A" << endl;
			else if (m + f >= 65 && m + f < 80) cout << "B" << endl;
			else if (m + f >= 50 && m + f < 65) cout << "C" << endl;
			else if (m + f >= 30 && m + f < 50) {
				if (r >= 50) cout << "C" << endl;
				else cout << "D" << endl;
			}
			else if (m + f < 30) cout << "F" << endl;
		}
		else cout << "F" << endl;
	}
}



Measured memory_bytes: 3092
n = int(input())
a = list(map(int,input().split()))
MAX = 10**6+1

is_divided = [0]*MAX 
is_appeared = [0]*MAX

for i in range(n):
  if not is_divided[a[i]]:
    if not is_appeared[a[i]]:
      is_appeared[a[i]] = 1
      k = a[i]*2
      while k < MAX:
        is_divided[k] = 1
        k += a[i]
    else:
      is_divided[a[i]] = 1
      
ans = 0      
for i in range(n):
  if not is_divided[a[i]]:
    ans += 1
print(ans)

Measured memory_bytes: 111864
using System;

class Watch {
    public static void Main() {

        int Seconds = int.Parse(Console.ReadLine());
        int Minutes = 0;
        int Hours = 0;

        while (Seconds >= 60) {
            Seconds -= 60;
            Minutes++;
        }
        while (Minutes >= 60) {
            Minutes -= 60;
            Hours++;
        }

        Console.WriteLine(Hours + ":" + Minutes + ":" + Seconds);
    }
}

Measured memory_bytes: 9136
#include<bits/stdc++.h>
#define ll long long int
#define fip ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define reptUsual(b) for(i=0; i<b; ++i)
#define reptArIn(i,a,b,ar) for( i=a; i<b; ++i) cin>>ar[i];
#define rept(i,a,b) for(i=a; i<b; ++i)
#define maX(a,b)    ( (a) > (b) ? (a) : (b))
#define miN(a,b)    ( (a) < (b) ? (a) : (b))
#define pb(a) push_back(a)
using namespace std;

class map2
{
    public:
    int per,  id;
    map2(int p , int i)
    {
        per=p;
        id=i;
    }
};

int main()
{
    int n;
    cin>>n;
    multimap <string , map2> mp;
    string s ;
    int p,i;
    rept(i,0,n)
    {
        cin>>s>>p;
        map2 *ob= new map2(p,i);
        mp.insert( pair<string ,map2> (s,*ob) );
    }

    multimap <string , map2> :: iterator itr1;
    multimap <string , map2> :: iterator itr2;
    int j;
    i=0;

    for(itr1=mp.begin() ; itr1!=mp.end() ; itr1++, i++)
    {
        itr2=itr1;
        itr2++;
        j=i+1;
        map <int ,int ,greater <int>> v;
        v.insert( pair<int ,int>( (itr1->second).per, (itr1->second).id + 1) );
        for(;;)
        {
            if(itr2==mp.end())
                break;

            if(! itr1->first.compare(itr2->first) )
            {
                v.insert( pair<int ,int>( (itr2->second).per, (itr2->second).id+ 1) );
                itr2++;
                i++;
                j++;
                itr1++;
                if(j==n)
                    break;
            }
            else
                break;
        }
        map <int , int> :: iterator itr3;

        for(itr3=v.begin() ; itr3!=v.end() ; itr3++)
        {
            cout<<itr3->second<<endl;
        }        

    }
    return 0;
}


Measured memory_bytes: 256
numero = int(input())
soma = 0
minimo = 100000
for aux in range(numero-1,1,-1):
    prim = str(aux)
    seg = str(numero - aux)
    for x in range(len(prim)):
        soma += int(prim[x])
    for x in range(len(seg)):
        soma += int(seg[x])
    if soma < minimo :
        minimo = soma
    soma = 0
if numero == 2:
    print(numero)
else:
    print(minimo)

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

void solve(std::string s, long long K) {
  vector<string> tmp;
  for(int i = 0;i<s.size();i++){
    for(int i1 = i;i1<min((int)s.size(),i+5);i1++){
      tmp.push_back(s.substr(i,i1-i+1));
    }
  }
  sort(tmp.begin(),tmp.end());
  tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
  cout<<tmp[K-1];
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  std::string s;
  std::cin >> s;
  long long K;
  scanf("%lld", &K);
  solve(s, K);
  return 0;
}


Measured memory_bytes: 1660
n = int(input())
a = list(map(int, input().split()))
m = 10 ** 9 + 7
s = sum(a) % m


sum = 0

for i in range(n):
  s -= a[i]
  if s < 0:
    s += m
  sum += a[i] * s
  sum %= m

print(sum)

Measured memory_bytes: 94252
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" }

T = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"

de = dict()
for i in range(32):
    s = "{:05b}".format(i)
    ch = T[i]
    de[ch] = s

de2 = dict()
for k, v in L.items():
    de2[v] = k

while True:
    try:
        t = input()
    except:
        break
    codebit = ""
    for i in t:
        codebit += de[i]

    s = ""
    while True:
        if len(codebit) == 0:
            break
        if len(codebit) < 6 and int(codebit,2) == 0:
            break
        for k in range(3,9):
            if codebit[:k] in de2:
                s += de2[codebit[:k]]
                codebit = codebit[k:]
                break
    print(s)




Measured memory_bytes: 5604
from functools import reduce

mod = 10 ** 9 + 7
def madd(x, y):
    ret = x + y
    return ret if ret < mod else ret - mod
def msub(x, y):
    ret = mod + x - y
    return ret if ret < mod else ret - mod
def mmul(x, y):
    return (x * y) % mod
def mpow(x, n):
    ret = 1
    while n > 0:
        if n & 1 > 0:
            ret *= x
            ret %= mod
        x = (x * x) % mod
        n >>= 1
    return ret

def msum(a):
    return reduce(madd, a, 0)

n, k = map(int, input().split())
INF = - (2**60)
dp = [-INF] * (k + 1)

for g in range(k, 0, -1):
    dp[g] = msub(mpow(k // g, n), msum(dp[2 * g::g]))

print(msum([mmul(g, dp[g]) for g in range(1, k + 1)]))


Measured memory_bytes: 15832
N, M = map(int, input().split())
ab = [[int(i) for i in input().split()] for j in range(N)]
cd = [[int(i) for i in input().split()] for j in range(M)]
for i in range(N):
    ans = 0
    dis = abs(ab[i][0] - cd[ans][0]) + abs(ab[i][1] - cd[ans][1])
    for nth in range(1, M):
        if abs(ab[i][0] - cd[nth][0]) + abs(ab[i][1] - cd[nth][1]) < dis:
            ans = nth
            dis = abs(ab[i][0] - cd[ans][0]) + abs(ab[i][1] - cd[ans][1])
    print(ans + 1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
const long long INF=1145141919,MOD=1e9+7;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const double EPS = 1e-9;    // 許容誤差。問題によって変える
//typedef complex<double> P;  // Point
//typedef vector<P> VP; //単純多角形
//#define X real()
//#define Y imag()
//#define LE(n,m) ((n) < (m) + EPS)
//#define GE(n,m) ((n) + EPS > (m))
//#define EQ(n,m) (abs((n)-(m)) < EPS)
//namespace std{
//    bool operator < (const P a, const P b){
//        return a.X != b.X ? a.X <b.X : a.Y < b.Y;
//    }
//}
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
//外積cross(a,b) = |a||b|sinθ
//double cross(const P& a, const P& b) {
 // return imag(conj(a)*b);
//}
//内積dot(a,b) = |a||b|cosθ
//double dot(const P& a, const P& b) {
  //return real(conj(a)*b);
//}
//Line
//struct L : public vector<P> {
  //L(const P &a, const P &b) {
    //push_back(a); push_back(b);
  //}
//};
//円
//struct C{
//  P p; double r;
//  C(const P &p, double r) : p(p), r(r) { }
//};
int main(){
    int max=123456*2+1;
    int sosu[max];
    for(int i=0;i<max;i++) sosu[i]=1;
    for(int i=2;i<sqrt(max);i++){
        for(int t=i+1;t<max;t++){
            if(t%i==0) sosu[t]=0;
        }
    }
    int sum=0;
    for(int i=0;i<max;i++){
        sum+=sosu[i];
        sosu[i]=sum;
    }
    int n;cin>>n;
    while(n){
        cout<<sosu[2*n]-sosu[n]<<endl;
        cin>>n;
    }
    return 0;
}



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

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

    int flag = 1;
    int counter = 0;
    while(flag){
        flag = 0;
        for(int i = N-1; i >= 0; i--){
            if(array[i] < array[i-1]){
                int temp;
                temp = array[i];
                array[i] = array[i-1];
                array[i-1] = temp;
                flag = 1;
                counter += 1;
            }
        }
    }

    for(int i = 0; i < N; i++){
        if(i == N-1) cout << array[i] << endl;
        else cout << array[i] << " ";
    }
    cout << counter << endl;
    
    return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long INF = 1e7;
const long long N = 1e6 + 7;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;

ll T = 1, n, m, b, ans, y, x, c, a, cnt, mn = 1e18;
string s;
vector < ll > v, v1;
set< char > st;
int main(){
    TIME
    cin >> a >> b >> m;
    ll l[a], r[b];
    for ( int i=0; i<a; i++ )
        cin >> l[i];
    for ( int i=0; i<b; i++ )
        cin >> r[i];
    for ( int i=0; i<m; i++ ){
        cin >> x >> y >> c;
        mn = min( mn, (l[x - 1] + r[y - 1]) - c );
    }
    cout << min( mn, (*min_element( l, l + a ) + *min_element(r, r + b)) );

}


Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] t = cin.ArrayInt(N);
        int[] v = cin.ArrayInt(N);
        int sumT = t.Sum() * 2;
        double[] V = new double[sumT + 1];
        int now = 0;
        for (int i = 1; i < sumT; i++)
        {
            V[i] = 99999999;
        }
        for (int i = 0; i < N; i++)
        {
            int next = now + t[i] * 2;
            for (int j = now; j <= next; j++)
            {
                V[j] = Math.Min(V[j], v[i]);
            }
            now = next;
        }

        for (int i = 1; i <= sumT; i++)
        {
            V[i] = Math.Min(V[i - 1] + 0.5, V[i]);
        }

        for (int i = sumT - 1; i >= 0; i--)
        {
            V[i] = Math.Min(V[i + 1] + 0.5, V[i]);
        }
        double ans = 0;
        for (int i = 0; i < sumT; i++)
        {
            ans += (V[i] + V[i + 1]) / 2;
        }
        Console.WriteLine(ans / 2);
    }
    
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13408
N = int(input())
S = [input() for _ in range(N)]

a = b = ab = ba = 0
for s in S:
    if s[0] == 'B' and s[-1] == 'A':
        ba += 1
    elif s[0] == 'B':
        b += 1
    elif s[-1] == 'A':
        a += 1
    ab += s.count('AB')

p = min([ba, a, b])
ab += 2*p
ba -= p
a -= p
b -= p

if ba == 0:
    ab += min([a, b])
else:
    ab += ba
    if p == 0 and a == 0 and b == 0:
        ab -= 1

print(ab)


Measured memory_bytes: 3700
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<sstream>
using namespace std;
int main() {
  int N,K;
  cin >> N >> K;
  
  int ans = 1;
  for (int i=1; i<=N; i++) {
    int ans1 = ans * 2;
    int ans2 = ans + K;
    int mi = min(ans1,ans2);
    if (mi == ans1) ans = ans1;
    else ans = ans2;
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,i;
	int value[5];
	int g=0;int chi=0;int pa=0;
	int te=0;

	while(scanf("%d",&n))
	{	
		if(n==0)
		{
			break;
		}
		value[0]=n;
		if(n==1)
		{
			g++;
		}
		if(n==2)
		{
			chi++;
		}
		if(n==3)
		{
			pa++;
		}
		for(i=1;i<5;i++)
		{
			scanf("%d",&n);
			value[i]=n;
			if(n==1)
			{
				g++;
			}
			if(n==2)
			{
				chi++;
			}
			if(n==3)
			{
				pa++;
			}
		}
		if(g==5 || chi==5 || pa==5)
		{
			for(i=0;i<5;i++)
			{
				value[i]=3;
				printf("%d\n",value[i]);
			}
		}
		if(g==0 || chi==0 || pa==0)
		{
			if(g>0 && chi>0)
			{
				for(i=0;i<5;i++)
				{
					printf("%d\n",value[i]);
				}
			}
			if(chi>0 && pa>0)
			{
				for(i=0;i<5;i++)
				{
					if(value[i]==2)
					{
						puts("1");
					}
					else
					{
						puts("2");
					}
				}
			}
			if(g>0 && pa>0)
			{
				for(i=0;i<5;i++)
				{
					if(value[i]==3)
					{
						puts("1");
					}
					else
					{
						puts("2");
					}
				}
			}
			
		}
		else
		{
			for(i=0;i<5;i++)
			{
				value[i]=3;
				printf("%d\n",value[i]);
			}
		}
		g=0;chi=0;pa=0;
	}
}

Measured memory_bytes: 612
import sys
n = int(input())
card =[]
for i in range(n):
    card.append(str(input()))
#print(card)
	
for i in range(1,14):
	if 'S '+str(i) in card:
		print('', end='')
	else:
		print('S '+str(i))
		
for i in range(1,14):		
	if 'H '+str(i) in card:
		print('', end='')
	else:
		print('H '+str(i))
		
for i in range(1,14):		
	if 'C '+str(i) in card:
		print('', end='')
	else:
		print('C '+str(i))
		
for i in range(1,14):		
	if 'D '+str(i) in card:
		print('', end='')
	else:
		print('D '+str(i))

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

int main() { /* ここに書く */
  
  int C,N;
  C=1;
  cin >> N;
  vector<string>vec(N);
  
  for(int i = 0; i<N ; i++){
    cin >> vec.at(i);}
  
  sort(vec.begin(),vec.end());

  for(int i = 1; i<N ; i++){
    if(vec.at(i) != vec.at(i-1)){
      C++;}
  }
  
  cout << C << endl;
  
}

Measured memory_bytes: 9596
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;

#define MAX_N 15
int matrix[MAX_N][MAX_N];
void init(){
	rep(i,MAX_N){
		rep(j,MAX_N){
			matrix[i][j] = -1;
		}
	}
}

int countBit(int bit,int n){
	int ans = 0;
	for(int i = 0; i < n; i++){
		if( bit & (1<<i)) ans++;
	}
	return ans;
}

int main()
{
	init();
	int n;
	cin>>n;
	rep(i,n){
		int a;
		cin>>a;
		rep(j,a){
			int x,y;
			cin>>x>>y;
			x = x -1;
			matrix[i][x] = y;
		}
	}
	int ans = 0;
	for(int bit = 0; bit < (1<<n);bit++){
		bool canBeEstablished = true;
		for(int i = 0; i < n; i++){
			if( bit & (1<<i)){
				for(int j = 0; j < n; j++){
					if( matrix[i][j] == 1 && !(bit & (1<<j))){
						canBeEstablished = false;
						break;
					}
					if( matrix[i][j] == 0 && (bit & (1<<j))){
						canBeEstablished = false;
						break;
					}
				}
			}
		}
		if( canBeEstablished == true){
			ans = max(ans,countBit(bit,n));
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n >> m) {
        ll ans = 0;
        REPS(i, n) ans += (i % m) == 0;
        ans = ans * ans * ans;
        if (m % 2 == 0) {
            ll sum = 0;
            REPS(i, n) {
                sum += i % m == m / 2;
            }
            ans += sum * sum * sum;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1<<29
#define LLINF 1LL<<60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}

ll N;
ll fact[100010];
ll ifact[100010];

ll modcomb(ll n, ll k){
    if(k < 0 || k > n) return 0;
    ll ans = fact[n];
    ans = ans * ifact[k] % MOD;
    ans = ans * ifact[n-k] % MOD;
    return ans;
}

int main() {
    scanf("%llu", &N);
    vector<ll> cnt(N+1, -1);
    ll a, d1, d2;
    REP(i, N) {
        scanf("%llu", &a);
        if(cnt[a] != -1) {
            d1 = min(cnt[a], ll(i));
            d2 = max(cnt[a], ll(i));
            break;
        }
        cnt[a] = i;
    }
    fact[0] = 1;
    ifact[0] = 1;
    FOR(i, 1, N+2) {
        fact[i] = fact[i-1] * i % MOD;
        ifact[i] = modpow(fact[i], MOD-2);
    }
    ll ans;
    printf("%lld\n", N);
    FOR(k, 2, N) {
        ans = modcomb(N-1, k) % MOD;
        ans = (ans + 2 * modcomb(N-1, k-1)) % MOD;        
        ans = (ans - modcomb(N-1-(d2-d1-1), k-1) + MOD) % MOD;
        ans = (ans + modcomb(N-1, k-2)) % MOD;
        printf("%llu\n", ans);
    }
    printf("1\n");
 	return 0;
}

Measured memory_bytes: 3584
x,y = map(int, input().split())
while 1:
    if x == 0 and y == 0:
        break
    if x > y:
        tmp = x
        x = y
        y = tmp
        print("{} {}".format(x, y))
        x,y = map(int, input().split())
    else:
        print("{} {}".format(x, y))
        x,y = map(int, input().split())



Measured memory_bytes: 5616
#include<stdio.h>
int gcd(int a,int b);
 
int main(void) {
	int N;
	int ans;
	int A[100000];
 
	scanf("%d", &N);
	for (int i = 0; i < N; i++) 
	{
		scanf("%d",&A[i]);
	}
 
	for (int i = 0; i < N - 1; i++) {
		ans = gcd(A[i], A[i + 1]);
		A[i + 1] = ans;
	}
	printf("%d\n",ans);
	
	return 0;
}
 
 
 
 
int gcd(int a,int b)
{
	int tmp;
	if (a < b) {
		tmp = b;
		b = a;
		a = tmp;
	}
  
	int r = a%b;
	while (r!=0) {
		a = b;
		b = r;
		r = a%b;
	}
 
	return b;
}

Measured memory_bytes: 512
#include<stdio.h>
#define INFINITY 1000000000

int main(){
	int map[11][11];
	int load;
	int a, b, time;
	int many;
	int i, j, k;
	int ans[11];
	int min;
	int answer;
	while(scanf("%d", &load) != 0){
		if(load == 0) break;
		min = INFINITY;
		many = 0;
		for(i = 0; i < 11; i++) ans[i] = 0;
		for(i = 0; i < 11; i++){
			for(j = 0; j < 11; j++){
				if(i == j){
					map[i][j] = 0;
					continue;
				}
				map[i][j] = INFINITY;
			}
		}
		for(i = 0; i < load; i++){
			scanf("%d %d %d", &a, &b, &time);
			map[a][b] = time;
			map[b][a] = time;
			if(many < a) many = a;
			if(many < b) many = b;
		}
		for(i = 0; i <= many; i++){
			for(j = 0; j <= many; j++){
				for(k = 0; k <= many; k++){
					if(map[j][k] > map[j][i] + map[i][k]) map[j][k] = map[j][i] + map[i][k];
				}
			}
		}
		for(i = 0; i <= many; i++){
			for(j = 0; j <= many; j++) ans[i] += map[i][j];
			if(min > ans[i]){
				min = ans[i];
				answer = i;
			}
		}
		printf("%d %d\n", answer, min);
	}
	return 0;
}

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

int link[200101], sze[200101],link1[200101],sze1[200101], n, k, l, x, y;
map<pair<int, int>, int> m;

int fnd(int a, int f[]){
while(a!=f[a])a=f[a];
return a;
}

void unite(int a, int b, int f[], int g[]){
a = fnd(a, f);
b = fnd(b, f);
if(g[a]<g[b])swap(a, b);
f[b]=a;
g[a]+=g[b];

}

int main(){
cin >> n >> k >> l;
for(int i =1; i<=n; i++)link[i]=i, sze[i]=1, link1[i]=i, sze1[i]=1;
for(int i =1; i<=k; i++){
    cin >> x >> y;
    if(fnd(x, link)!=fnd(y, link))unite(x, y, link, sze);
}
for(int i =1; i<=l; i++){
    cin >> x >> y;
    if(fnd(x, link1)!=fnd(y, link1))unite(x, y, link1, sze1);
}

for(int i=1; i<=n; i++){
    int a = fnd(i, link); int b = fnd(i, link1);
    m[{a,b}]++;
}

for(int i =1; i<=n; i++){
    int a = fnd(i, link); int b = fnd(i, link1);
    cout << m[{a,b}] << " ";
}

return 0;}


Measured memory_bytes: 15104
import copy

n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

asum = [0]
bsum = [0]
tmp = 0
for i in range(n):
    tmp += a[i]
    asum.append(tmp)
tmp = 0
for i in range(m):
    tmp += b[i]
    bsum.append(tmp)


ans = 0
nb = copy.deepcopy(m)
for na in range(n+1):
    res = k - asum[na]
    if res < 0:
        break
    flg = True
    while flg:
        if bsum[nb] > res:
            nb -= 1
            continue
        ans = max(ans, na+nb)
        break
print(ans)

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

int main()
{
    int n;
    cin >> n;
    n = n % 10;

    if(n==3)
    {
        cout << "bon" << endl;
    }
    else if((n==0)||(n==1)||(n==6)||(n==8))
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "hon" << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
from itertools import product

# 入力
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

# 整数 i を 0 に書き換えるのに必要な魔力の最小量を求める
G = [{} for _ in range(10)]
for i, j in product(range(10), repeat=2):
    G[i][j] = c[i][j]
INF = 10**10


def warshall_floyd(G):
    dp = [
        [
            0 if i == j else
            G[i][j] if j in G[i] else
            INF
            for j in range(len(G))
        ]
        for i in range(len(G))
    ]
    for k in range(len(G)):
        for i in range(len(G)):
            for j in range(len(G)):
                dp[i][j] = (
                    dp[i][j] if dp[i][k] == INF or dp[k][j] == INF else
                    min(dp[i][j], dp[i][k] + dp[k][j])
                )
    return dp


dp = warshall_floyd(G)
# すべての数字について、dp を用いて解を求める
ans = sum(
    dp[x][1]
    for a in A
    for x in a
    if x >= 0
)

# 出力
print(ans)


Measured memory_bytes: 3444
while True :
    H, W = map(int, input().split())
    if H == 0 :
        break
    else :
        for i in range(H) :
            for j in range(W) :
                if (i + j) % 2 == 0 :
                    print("#", sep = "", end = "")
                else :
                    print(".", sep = "", end = "")
            print()
        print()


Measured memory_bytes: 7000
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
#define repeat(i,n) forloop(i, 0, n)
#define forloop(i, a, b) for(int i=(a);i<(b);++i)
#define debug(x) cerr << #x << ": " << x << " " << "(L:" << __LINE__ << ")" << '\n'
template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; };
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; };
const int MOD = 1e9 + 7;
const int64 INF64 = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;

struct point {
    int x;
    int y;
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<bool> reached[3];
    vector<int> dist[3];
    unordered_map<int, set<int>> linked_nodes;

    repeat(i, 3){
        reached[i].resize(n, false);
        dist[i].resize(n, INF);
    }

    repeat(i, m){
        int a, b; cin >> a >> b;
        linked_nodes[a-1].insert(b-1);
    }

    int s, t; cin >> s >> t;
    s--; t--;
    dist[0][s] = 0;
    queue<pair<int, int>> q;
    q.push(make_pair(0, s));
    while(not q.empty()){
        int step = q.front().first;
        int node = q.front().second;
        int next_step = (step + 1) % 3;
        q.pop();
        for(auto next_node: linked_nodes[node]){
            if(reached[next_step][next_node]) continue;
            q.push(make_pair(next_step, next_node));
            reached[next_step][next_node] = true;
            if(step == 2){
                chmin(dist[next_step][next_node], dist[step][node]+1);
            }else{
                chmin(dist[next_step][next_node], dist[step][node]);
            }
        }
    }

    if(dist[0][t] == INF) cout << -1 << endl;
    else cout << dist[0][t] << endl;
    return 0;
}

Measured memory_bytes: 15012
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n,m;
	while(cin>>n>>m,n+m)
	{
		int b[n+2];
		bool a[m+2][740]={};
		int r;
		cin>>r;
		for (int i = 0; i < r; ++i)
		{
			int w,x,y;
			bool z;
			cin>>w>>x>>y>>z;
			if(z) b[x]=w-540;
			else
			{
				for (int j = b[x]; j < w-540; ++j)
				{
					a[y][j]=1;
				}
			}
		}
		int q; 
		cin>>q;
		for (int i = 0; i < q; ++i)
		{
			int t1,t2,t3,ans=0;
			cin>>t1>>t2>>t3;
			for (int j = t1-540; j < t2-540; ++j) ans+=a[t3][j];
			cout<<ans<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 10004
#include <cstdio>
#include <cstring>
int H, W, T, a[1009][1009], dp[1009][1009];
int main() {
	while (scanf("%d%d%d", &H, &W, &T), H) {
		getchar();
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				a[i][j] = getchar_unlocked() - 48; getchar_unlocked();
			}
		}
		memset(dp, 0, sizeof(dp));
		dp[0][0] = T - 1;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				dp[i + 1][j] += (dp[i][j] - a[i][j] + 1) >> 1;
				dp[i][j + 1] += (dp[i][j] + a[i][j]) >> 1;
			}
		}
		int cx = 0, cy = 0;
		while (cx < H && cy < W) {
			if ((dp[cx][cy] ^ a[cx][cy]) & 1) cy++;
			else cx++;
			T >>= 1;
		}
		printf("%d %d\n", cx + 1, cy + 1);
	}
	return 0;
}

Measured memory_bytes: 10596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    string before = "";
    int number = 0;
    cout << number << "\n";
    cout.flush();
    before = in<string>();
    bool plus = 1;
    for (int i = 19; i >= 0; i--){
        if(before == "Vacant")break;
        if(plus == 0 || number+(1<<i) < N){
            if(plus){
                number+=(1<<i);
            }else{
                number-=1<<i;
            }
            cout << number << "\n";
            cout.flush();
            string tmp = in<string>();
            if(tmp == before){
                plus = 1;
            }else if(tmp == "Vacant"){
                break;
            }else{
                plus = 0;
            }
        }
        cout.flush();
    }
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    ll x[100010], y[100010];
    cin >> N >> M;
    rep(i,0,M){
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
    }
    ll ans = 0;
    ll is_red[100010] = {};
    is_red[0] = 1;
    ll cnt[100010] = {};
    rep(i,0,N){
        cnt[i] = 1;
    }
    rep(i,0,M){
        if(is_red[x[i]] == 1){
            if(cnt[x[i]] == 1){
                is_red[x[i]] = 0;
                is_red[y[i]] = 1;
                cnt[x[i]]--;
                cnt[y[i]]++;
            }else{
                is_red[y[i]] = 1;
                cnt[x[i]]--;
                cnt[y[i]]++;
            }
        }else{
            cnt[x[i]]--;
            cnt[y[i]]++;
        }
    }
    rep(i,0,N){
        if(is_red[i] == 1) ans++;
    }
    print(ans);
}


Measured memory_bytes: 3328
#include "bits/stdc++.h"

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll LL_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main(){
    ll A, B, K;
    cin >> A >> B >> K;
    if(A >= K) cout << A - K << ' ' << B << endl;
    else cout << '0' << ' ' << max(B - (K - A), (ll)0) << endl;
}

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

int main(){
	int N = 0,M = 0;
	int lMax=-1,rMin=INT_MAX;
	int L, R,ans;
	cin >> N >> M;


	for (int i = 0; i < M; i++)
	{
		cin >> L >> R;

		lMax = max(lMax,L);
		rMin = min(rMin,R);

	}
	if(lMax <= rMin)ans = rMin - lMax + 1;
	else ans = 0;
	cout << ans << endl;

}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	char s[n][n];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> s[i][j];
		}
	}
	int ans = 0;
	for(int k = 0; k < n; k++){
		bool ok = true;
		for(int i = 0; i < n; i++){
			for(int j = i+1; j < n; j++){
				if(s[i][(j+k)%n] != s[j][(i+k)%n]) ok = false;
			}
		}
		if(ok) ans += n;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    string  s,t; 
    cin >> s >> t; 
    map <char,int> oc1,oc2;
    for (int i=0;i<sz(s);i++) oc1[s[i]]++;
    for (int i=0;i<sz(t);i++) oc2[t[i]]++;
    vector <int> a,b;
    for (auto &it: oc1) a.pb(it.ss); 
    for (auto &it: oc2) b.pb(it.ss); 
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if (a != b) cout << "No" << endl;
    else cout << "Yes"<< endl;
    return;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3900
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    string s;
    cin >> s;
    bool is_good = true;

    for (int i = 1; i < (int)s.size(); ++i) {
        if (s[i-1] == s[i]) is_good = false;
    }

    if (is_good) cout << "Good" << endl;
    else cout << "Bad" << endl;
}


Measured memory_bytes: 256
/*******************************
Author:galaxy yr
LANG:C++
Created Time:2019/08/10 20:38:15
*******************************/
#include<iostream>
#include<cstdio>
using namespace std;
int k,x;
int main()
{
        //freopen("b.in","r",stdin);
        //freopen("b.out","w",stdout);
        cin>>k>>x;
        for(int i=x-k+1;i<=x+k-1;i++)
            cout<<i<<' ';
        cout<<endl;
        return 0;
}


Measured memory_bytes: 256