akhauriyash/Code-Regression huggingface dataset:
#define rep(i, n) for(int i = 0; i < n; i++)
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
	int X,N;
	cin >> X >> N;
	vector<int> p(N);
	rep(i,N) cin >> p[i];

	bool exact = true;
	rep(i,N) if (p[i]==X) exact = false;
	if (exact) {
		cout << X << endl;
		return 0;
	}

	int diff = 1;
	while(1) {
		int x_p = X + diff;
		int x_m = X - diff;
		bool flag_p, flag_m;
		flag_p = true, flag_m = true;
		rep(i,N) if (p[i]==x_m) flag_m = false;
		if (flag_m) {
			cout << x_m << endl;
			return 0;
		}
		rep(i,N) if (p[i]==x_p) flag_p = false;
		if (flag_p) {
			cout << x_p << endl;
			return 0;
		}
		diff++;
	}

	return 0;
}


Measured memory_bytes: 3596
import sys
C1 = input()
C2 = input()
if C1[0] != C2[2]:
    print('NO')
    sys.exit()
else:
    if C1[1] != C2[1]:
        print('NO')
        sys.exit()
    else:
        if C1[2] != C2[0]:
            print('NO')
            sys.exit()
print('YES')

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		sc.close();
		int len1 = S.length();
		int len2 = S.replace("ABC", "").length();
		System.out.println((len1-len2)/3);
	}
}

Measured memory_bytes: 21712
#include<iostream>

using namespace std;

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	if(a == b) 				printf("0\n");
	else if((a + b) & 1) 	printf("IMPOSSIBLE\n");
	else 					printf("%d\n", (a + b) >> 1); 		
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r, D;
  cin >> r >> D;
  vector<int> x(11);
  cin >> x.at(0);
  for(int i=1; i<11; i++){
    x.at(i) = r * x.at(i-1) -D;
    cout << x.at(i) << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N+1];
        int[] B = new int[N+1];
        int ansCount = 0;
        Vector<Integer> ans = new Vector<Integer>();
        for(int i=1;i<N+1;i++){
            A[i] = sc.nextInt();
        }

        for(int i=N;i > 0;i--){
            int count = 0;

            for(int j=2;i * j < N+1;j++){
                if(B[i * j] == 1){
                    count++;
                }
            }
            B[i] = (A[i] + count) % 2;
            ansCount += B[i];

        }
        System.out.println(ansCount);

        for(int i=1;i<N+1;i++){
            if(B[i] == 1){
                System.out.print(i + " ");
            }
        }



    }

}


Measured memory_bytes: 69972
#include <iostream>

using namespace std;

int main(){
  int a, b, c; cin >> a >> b >> c;

  int max;
  max = a;
  int max_ind = 0;

  if (max < b){
    max = b;
    max_ind = 1;
  }
  if ( max < c ){
    max = c;
    max_ind = 2;
  }

  int d1, d2;
  if (max_ind == 0){
    d1 = a - b;
    d2 = a - c;
  } else if (max_ind == 1){
    d1 = b - a;
    d2 = b - c;
  } else {
    d1 = c - a;
    d2 = c - b;
  }
  
  int ans;
  // 差が　奇偶で分ける
  // 両方偶
  if ( d1 % 2 == 0 && d2 % 2 == 0){
    ans = d1 / 2 + d2 / 2;
  } else if ( d1 % 2 == 1 && d2 % 2 == 1){
    ans = (d1-1) / 2 + (d2/-1) / 2 + 1;
  } else { // どちらかずつ
    ans = (d1 + d2 + 1)/2 + 1;
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N;
int L[220];
signed main() {
    cin>>N;
    for(int i=0;i<2*N;i++)cin>>L[i];
    sort(L,L+2*N);
    int ans=0;
    for(int i=0;i<2*N;i+=2)ans+=L[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
typedef long long ll;
using namespace std;
int main() {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    c *= 2;

    if(a+b<=c) {
        cout << a*x + b*y << endl;
        return 0;
    }

    ll min = a*x + b*y;
    for(ll i=0; i<200000; i++) {
        ll z = i*c + max(0LL, x-i)*a + max(0LL, y-i)*b;
        if(min>z) min=z;
    }
    cout << min << endl;;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vl a(n);
  ll ans = 0;
  rep(i, n){
    cin >> a[i];
    if(i==0)continue;
    if(a[i]==a[i-1]){
      ans++;
      a[i] += MOD;
    }
  }
  print(ans);
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(size_t i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(size_t i=(b)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))
#define Yes out("Yes")
#define No out("No")
#define NO out("NO")
#define YES out("YES")
#define INF INT_MAX/2
#define ShowAll(collection) for(auto i:collection){out(i);}
template<typename T> pair<vector<T>,int> getAuto() {int N; cin >> N; pair<vector<T>, int> rt;rt.first.resize(N);rt.second = N;REP(i, N) cin >> rt.first[i];return rt;}
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }

int main(){
	int N;
	cin >> N;
	out(N * 800 - (N / 15) * 200);
}



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

int main(){
    int n,mx=0;
    string s;
    cin >> n;
    map<string,int> m;

    for(int i=0;i<n;i++){
        cin >> s;
        m[s]++;
        if(m[s]>mx){
            mx=m[s];
        }
    }
    for(auto p:m){
        if(p.second == mx){
            cout << p.first << endl;
        }
    }
}

Measured memory_bytes: 25216
n,m=map(int,input().split())
graph=[[] for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

def dfs(v, seen):
    if all(seen):
        return 1
    ans=0
    for vv in graph[v]:
        if seen[vv]:
            continue
        seen[vv]=True
        ans+=dfs(vv, seen)
        seen[vv]=False
    return ans

seen=[False]*n
seen[0]=True
print(dfs(0, seen))


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

public class Main{
    
    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int times;

        try{
            while((times = Integer.parseInt(br.readLine())) != 0){
                //initialize
                int[] dice = {1,2,3,5,4,6};
                int score = 1;

                for(int i = 0; i < times; i++){
                    rotate(br.readLine() , dice);
                    score += dice[0];
                }

                System.out.println(score);

            }
        }catch(IOException e){
            e.printStackTrace();
        }

    }
    

    private static void rotate (String order , int[] dice){
        int tmp;
        switch(order){
            case "North":
                tmp = dice[0];
                dice[0] = dice[1];
                dice[1] = dice[5];
                dice[5] = dice[3];
                dice[3] = tmp;
                break;
            case "East":
                tmp = dice[0];
                dice[0] = dice[4];
                dice[4] = dice[5];
                dice[5] = dice[2];
                dice[2] = tmp;
                break;
            case "South":
                tmp = dice[0];
                dice[0] = dice[3];
                dice[3] = dice[5];
                dice[5] = dice[1];
                dice[1] = tmp;
                break;
            case "West":
                tmp = dice[0];
                dice[0] = dice[2];
                dice[2] = dice[5];
                dice[5] = dice[4];
                dice[4] = tmp;
                break;
            case "Left":
                tmp = dice[1];
                dice[1] = dice[4];
                dice[4] = dice[3];
                dice[3] = dice[2];
                dice[2] = tmp;
                break;
            case "Right":
                tmp = dice[1];
                dice[1] = dice[2];
                dice[2] = dice[3];
                dice[3] = dice[4];
                dice[4] = tmp;
                break;
        }
    }
}

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

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define ll long long
#define pii pair<int, int>
#define is insert
#define er erase

using namespace std;

const int MAX_N = 1e2 + 1;

int solve();

#define TASK ""

int main()
{
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
        //freopen(TASK".in", "r", stdin);
        //freopen(TASK".out", "w", stdout);
    #endif // DEBUG
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

int n;
int ind;

int a[MAX_N];

ll sum = 0;
ll ans;

int solve()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        sum += a[i];
    }
    ind = 1;
    ans = abs(sum - n * a[1]);
    for (int i = 2; i <= n; ++i)
    {
        if (abs(sum - n * a[i]) < ans)
        {
            ans = abs(sum - n * a[i]);
            ind = i;
        }
    }
    cout << ind - 1 << endl;
    return 0;
}




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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL << 25) // 33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}, w, h, res;
string a[55];
bool isw = false, isb = false;

int dfs(int y, int x) {
  a[y][x] = '#';
  res++;
  REP(i, 4) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx >= 0 && nx < w && ny >= 0 && ny < h) {
      if (a[ny][nx] == '.')
        dfs(ny, nx);
      if (a[ny][nx] == 'W')
        isw = true;
      if (a[ny][nx] == 'B')
        isb = true;
    }
  }

  return res;
}

signed main(void) {
  while (true) {
    cin >> w >> h;
    if(!w && !h) break;
    REP(i, h) cin >> a[i];

    int nw = 0, nb = 0;
    REP(i, h) REP(j, w) {
      if (a[i][j] == '.') {
        // cout << a[i][j] << " ";
        isw = false;
        isb = false;
        res = 0;
        dfs(i, j);
        if (isw && !isb)
          nw += res;
        else if (!isw && isb)
          nb += res;
        // cout << res << " " << i << " " << j << " " << nb << " " << nw <<
        // endl;
      }
    }

    cout << nb << " " << nw << endl;
  }
  return 0;
}

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

int main() {
  int n; cin >> n;
  string s; cin >> s;
  int x = 0;
  int max_num = x;
  
  for (int i = 0; i < n; ++i) {
    char ope = s[i];
    if (ope == 'I') ++x;
    else if (ope == 'D') --x;
    
    max_num = max(max_num, x);
  }
  
  cout << max_num << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5; 


string s;
int main(){
	map<string,int>m;
	int n;
	cin>>n;
	while(n--){
		cin>>s;
		m[s]++;
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"];
	return 0;
}

Measured memory_bytes: 3624
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

void solve (string s)
{
    int ans = sz(s);
    forn (let, 26)
    {
        int cur = 0;
        forn (r, sz(s) + 1) forn (l, r)
        {
            bool ok = true;
            for (int m = l; m < r; m++)
                ok &= (s[m] != let + 'a');
            if (ok)
                cur = max(cur, r - l);
        }
        ans = min(ans, cur);
    }

    cout << ans << endl;
}

int main()
{
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    while (cin >> s)
        solve(s);
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(int, char**)
{
    string s;
 
    cin >> s;
 
    bool result = false;
    for (int i = 0; i < s.length(); i++)
        if (s[i] == '7') result = true;
 
    if (result) cout << "Yes" << endl;
    else cout << "No" << endl;
 
    return 0;
}

Measured memory_bytes: 3624
n,k=map(int,input().split())

s=[]
for i in range(1,n+1):
  s.append(i%k)

from collections import Counter
dic=Counter(s)

ans=0
for a in dic:
  if (2*a)%k==0:
    ans=ans+dic[a]*dic[(k-a)%k]*dic[(k-a)%k]
    
print(ans)

  
  



Measured memory_bytes: 20848
import math

A, B = map(int, input().split())
flag = True
count = B-A+1
for i in range(A, B+1):
    for j in range(int(math.ceil(len(str(A)))/2)):
        if str(i)[j] != str(i)[-1-j]:
            count -= 1
            break
print(count)


Measured memory_bytes: 3060
#include <iostream>

int returnEra(int y,int m,int d)
{
    /*  pre-meiji:0
        meiji:1
        taisho:2
        showa:3
        heisei:4*/

    if (y > 1989) return 4;
    if (y ==1989){
        if (m > 1) return 4;
        if (m ==1 && d>=8) return 4;
    }

    if (y > 1926) return 3;
    if (y ==1926){
        if (m > 12) return 3;
        if (m ==12 && d >=25) return 3;
    }

    
    if (y > 1912) return 2;
    if (y ==1912){
        if (m > 7) return 2;
        if (m ==7 && d >=30) return 2;
    }

    
    if (y > 1868) return 1;
    if (y ==1868){
        if (m > 9) return 1;
        if (m ==9 && d >=8) return 1;
    }

    return 0;
}

int main()
{
    int y,m,d;
    int era;
    while (std::cin >> y >> m >> d) {
        era=returnEra(y,m,d);

        if (era==0) std::cout << "pre-meiji\n";
        if (era==1) std::cout << "meiji " << (y-1867) << " " << m << " " << d << std::endl;
        if (era==2) std::cout << "taisho " << (y-1911) << " " << m << " " << d << std::endl;
        if (era==3) std::cout << "showa " << (y-1925) << " " << m << " " << d << std::endl;
        if (era==4) std::cout << "heisei " << (y-1988) << " " << m << " " << d << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3044
import java.util.Scanner;

public class Main {

    static long count = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        mergeSort(a, 0, n);
        System.out.println(count);
    }

    private static void mergeSort(int[] s, int left, int right) {
        if (left + 1 < right) {
            int mid = (left + right) / 2;
            mergeSort(s, left, mid);
            mergeSort(s, mid, right);
            merge(s, left, mid, right);
        }
    }

    private static void merge(int[] s, int left, int mid, int right) {
        int[] L = new int[mid - left + 1];
        int[] R = new int[right - mid + 1];
        System.arraycopy(s, left, L, 0, L.length - 1);
        System.arraycopy(s, mid, R, 0, R.length - 1);
        L[L.length - 1] = Integer.MAX_VALUE;
        R[R.length - 1] = Integer.MAX_VALUE;
        for (int i = 0, j = 0, k = left; k < right; k++) {
            if (L[i] <= R[j]) {
                s[k] = L[i];
                i++;
                count += j;
            } else {
                s[k] = R[j];
                j++;
            }
        }
    }
}

Measured memory_bytes: 102784
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main(){
	int a = 0, b = 0, c[100000], d[100000], e[100000], count = 0;
	char uc[100000];
	cin >> a>>b;
	if (a % 500 > b) {
		cout << "No" << endl;
	}
	else { cout << "Yes" << endl; }
	return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s;cin >> s;
    ll k; cin >> k;
    rep(i,k){
        if(s[i] != '1'){
            out(s[i]);
            return 0;
        }
    }
    out('1');
}


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

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let p: usize = iterator.next().unwrap().parse().unwrap();

    let mut is_all_even: bool = true;
    for _ in 0..n {
        let a: usize = iterator.next().unwrap().parse().unwrap();
        if a % 2 == 1 {
            is_all_even = false;
            break;
        }
    }

    if is_all_even {
        if p == 0 {
            format!("{}", 2_u64.pow(n as u32))
        } else {
            format!("{}", 0)
        }
    } else {
        format!("{}", 2_u64.pow((n - 1) as u32))
    }
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define msg(a) cout << #a << " " << a << endl
#define eb emplace_back

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

    int a = stoi(S.substr(0, 2));
    int b = stoi(S.substr(2, 4));

    bool YYMM_flag = false;
    bool MMYY_flag = false;
    if (a >= 1 && a <= 12) {
        MMYY_flag = true;
    }
    if (b >= 1 && b <= 12) {
        YYMM_flag = true;
    }

    if (YYMM_flag && MMYY_flag) {
        cout << "AMBIGUOUS" << endl;
    }
    else if (YYMM_flag) {
        cout << "YYMM" << endl;
    }
    else if (MMYY_flag) {
        cout << "MMYY" << endl;
    }
    else {
        cout << "NA" << endl;
    }

    return 0;
}



Measured memory_bytes: 384
import sys
count = int(input())
a = list(map(int, input().split()))
#0が出た時点で終了する
for i in a:
    if i == 0:
        print(0)
        sys.exit()
#合計の計算        
total = 1
for j in a:
    total = total*j
    #10^18超えた時点で終了する
    if total>10**18:
        print(-1)
        sys.exit()

print(total)


Measured memory_bytes: 21772
import java.util.Scanner;

public class Main {
    static char[] c;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        boolean b = s.charAt(2) == s.charAt(3);
        boolean b2 = s.charAt(4) == s.charAt(5);

        System.out.println(b&&b2?"Yes":"No");
    }
}

Measured memory_bytes: 21844
n = int(input())
a = list(map(int, input().split()))
ans = 0
while True:
  b = 0
  for i in range(n):
    if a[i] % 2 != 0:
      print(ans)
      exit()
    else:
      a[i] = a[i] /2
      b += 1
  if b % n == 0:
    ans += 1
  else:
    print(ans)
    exit()

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

template <size_t N>
int print(std::bitset<N>& b, int n) {
    for (int i = 0; i < n; i++) std::cout << (b[i] ? 'B' : 'A');
    std::cout << std::endl;

    return 0;
}

int main() {
    int n, k;
    std::string s;
    std::cin >> n >> k >> s;
    std::bitset<210000> b;
    // A -> 0, B -> 1
    for (auto i = 0; i < s.size(); i++) {
        b[i] = s[i] == 'B';
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (i + cnt == k) return print(b, n);
        if (!b[0]) {
            cnt++;
            if (i + cnt == k) {
                b[0] = true;
                return print(b, n);
            }
        }
        b >>= 1;
        b = ~b;
        b[n - 1] = false;
    }

    if (n % 2) {
        std::cout << ((k - n - cnt) % 2 ? 'B' : 'A');
        for (int i = 1; i < n; i++) std::cout << (i % 2 ? 'B' : 'A');
    } else {
        for (int i = 0; i < n; i++) std::cout << (i % 2 ? 'A' : 'B');
    }

    std::cout << std::endl;

    return 0;
}

Measured memory_bytes: 900
import numpy as np
a_l = [ list(map(int, input().split())) for _ in range(3) ]
m_l = np.array([ [0]*3 for _ in range(3) ])
n = int(input())
b_l = [ int(input()) for _ in range(n) ]

def check_bingo(m_l):
    if sum(m_l[0]) == 3:
        return True
    if sum(m_l[1]) == 3:
        return True
    if sum(m_l[2]) == 3:
        return True
    if sum(m_l[:,0]) == 3:
        return True
    if sum(m_l[:,1]) == 3:
        return True
    if sum(m_l[:,2]) == 3:
        return True
    if sum([m_l[0,0],m_l[1,1],m_l[2,2]]  ) == 3:
        return True
    if sum([m_l[0,2],m_l[1,1],m_l[2,0]]  ) == 3:
        return True
    return False

for b in b_l:
    for i,a in enumerate(a_l):
        for j,v in enumerate(a):
            if b == v:
                m_l[i][j]=1
if check_bingo(m_l):
    print('Yes')
else:
    print('No')

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

long long Gcd(long long m, long long n)
{
	long long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}
long long Lcm(long long m, long long n)
{
	return m * n / Gcd(m,n); 
}
int main()
{
    long long A, B, C, D, L;
    long long count, ans;
    cin >> A >> B >> C >> D;
    if(C>D){
        L = Lcm(C,D);
    }else{
        L = Lcm(D,C);
    }
    count = (B/C+B/D-B/L) - ((A-1)/C+(A-1)/D-(A-1)/L);
    ans = B-A+1-count;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define rep(i, a, b) for(int i = a; i < b; i++)

using namespace std;

int main() {
	int x, sec;
	sec = 0;
	rep(i, 0, 4) {
		cin >> x;
		sec += x;
	}

	int min = 0;
	while(sec >= 60) {
		sec -=60;
		min ++;
	}
	cout << min << endl;
	cout << sec << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main() {
  string A, B;
  cin >> A >> B;
  int a = A.size();
  int b = B.size();
  if(a > b) {
    cout << "GREATER" << endl;
  }
  else if(b > a) {
    cout << "LESS" << endl;
  }
  else {
    for(int i = 0; i < a; i++) {
      if(A[i] > B[i]) {
        cout << "GREATER" << endl;
        break;
      }
      else if(B[i] > A[i]) {
        cout << "LESS" << endl;
        break;
      }
      if(i == a - 1) {
        cout << "EQUAL" << endl;
      }
    }
  }
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int MOD = 1e9 + 7;

typedef long long ll;
typedef pair<int, int> P;

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

	int ans = 0;
	if (s[0] == 'B') {
		bool x = false;
		for (int i = 1; i < s.size(); i++) {
			if (s[i] == 'B' && x == true) {
				x = false;
				ans++;
			}
			else if (s[i] == 'W' && x == false) {
				x = true;
				ans++;
			}
		}
	}
	else {
		bool x = false;
		for (int i = 1; i < s.size(); i++) {
			if (s[i] == 'W' && x == true) {
				x = false;
				ans++;
			}
			else if (s[i] == 'B' && x == false) {
				x = true;
				ans++;
			}
		}
	}
	cout << ans << endl;
}

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

int main(){
  int n, q, b, e;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  cin >> q;
  for(int i = 0; i < q; i++){
    cin >> b >> e;
    reverse(a.begin() + b, a.begin() + e);
  }
  for(int i = 0; i < n; i++){
    if(i > 0){
      cout << " ";
    }
    cout << a[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3092
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int x = scanner.nextInt();
		String s = String.format("%1$d:%2$d:%3$d", x / 3600, (x % 3600) / 60, x % 60);
		System.out.println(s);
	}

}

Measured memory_bytes: 17368
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

na, nb = 0, 0

suma = sum(a)
sumb = sum(b)
jdg = False

for i in range(N):
    while a[i]!= b[i]:
        if suma + na > sumb + nb:
            jdg = True
            break
        if i == N - 1:
            a[i] += na
            b[i] += nb
            if a[i] > b[i]:
                jdg = True
            break
        if a[i] > b[i]:
            ab = a[i] - b[i]
            if nb < ab:
                na += 2 * (ab - nb)
                nb = 0
            else: nb -= ab
            sumb += ab
            b[i] += ab
        else:
            ba = b[i] - a[i]
            if na < ba:
                nb += (ba - na + 1) // 2
                na = 0
            else: na -= ((ba+1)//2)*2
            if nb > 0: nb -= ba%2
            else: na += 2 * (ba%2)
            suma += ((ba+1)//2)*2
            sumb += ba%2
            a[i] += ((ba+1)//2)*2
            b[i] += ba%2
    if jdg: break
print('No' if jdg else 'Yes')

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
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 pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


ll a[220],b[220],c[220],d[220],e[22];
int main(){
    ll n,m,q,ans=0;
    cin>>n>>m>>q;
    rep(i,0,q)cin>>a[i]>>b[i]>>c[i]>>d[i];

    for(int mask = 0; mask < (1<<(m+n-1)); mask++){
        ll cnt=1,tmp=0;
        rep(i,0,m+n)if(mask&(1<<i)){e[cnt]=i-cnt+1;cnt++;}
        if(cnt!=n+1)continue;
        rep(i,0,q)if(e[b[i]]-e[a[i]]==c[i])tmp+=d[i];
        ans=max(ans,tmp);
    }
    cout<<ans;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int A, B, K, C;

int main(void){
	//IO("test.in", "test.out");
	scanf("%d%d%d", &A, &B, &K);
	for(int i = min(A, B); i > 0; i--){
		if(A % i == 0 && B % i == 0) C++;
		if(A % i == 0 && B % i == 0 && C == K){
			printf("%d\n", i);
			break;
		}
	}
}

Measured memory_bytes: 384
function Main(s){
  var n = +s;
  if(n === 0){console.log(0);return;}
  var ans = [], i = 1, j = 1;
  while(n && Math.abs(n) < 9e9){
    if(Math.abs(n) & i){
      ans.push(1);
      n -= j;
    }
    else ans.push(0);
    i *= 2;
    j *= -2;
  }
  console.log(ans.reverse().join(""));
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
// #define DEBUG

using namespace std;

const int N = 2e3+7;

int n;
int a[N];
long long res;

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    sort(a+1, a+n+1);
    for (int i = 1; i < n-1; ++i) {
        for (int j = i+1; j < n; ++j) {
            int l = a[j]-a[i], r = a[i]+a[j];
            // l < a[k] < r
            res += lower_bound(a+j+1, a+n+1, r)-upper_bound(a+j+1, a+n+1, l);
#ifdef DEBUG
            cout << res << endl;
#endif
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int x, y; cin >> x >> y;
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			if (i + j == x and 2 * i + 4 * j == y) {
				cout << "Yes" << "\n";
				return 0;
			}
		}
	}
	cout << "No" << "\n";
}


Measured memory_bytes: 3672
import java.util.*;
public class Main {
    static int mod=1000000007;
    static int drip(char a[][],int n,int m)
    {
        int dp[][]=new int[n][m];
        if(a[0][0]=='#')
        {
            return 0;
        }
        dp[0][0]=0;
        for(int i=1;i<m;i++)
        {
            if(a[0][i]=='#')
            {
                break;
            }
            dp[0][i]=1;
        }
        for(int i=1;i<n;i++)
        {
            if(a[i][0]=='#')
            {
                break;
            }
            dp[i][0]=1;
        }
        for(int i=1;i<n;i++)
        {
            for(int j=1;j<m;j++)
            {
                if(a[i][j]=='#')
                {
                    dp[i][j]=-1;
                }
                else
                {
                    if(dp[i-1][j]!=-1)
                    {
                        dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
                    }
                    if(dp[i][j-1]!=-1)
                    {
                        dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
                    }
                }
            }
        }
        if(a[n-1][m-1]=='#')
        {
            return 0;
        }
        return dp[n-1][m-1];
    }
    public static void main(String args[]) {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int m=s.nextInt();
        char a[][]=new char[n][m];
        String x="";
        for(int i=0;i<n;i++)
        {
            x=s.next();
            char b[]=x.toCharArray();
            for(int j=0;j<m;j++)
            {
                a[i][j]=b[j];
            }
        }
        System.out.println(drip(a,n,m));
    }
}

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

int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    int size = s.size();
    for(int i =0; i < size; i++){
        s[i] +=N;
        if (s[i] > 'Z')  s[i] -=26;
    }
    cout << s << endl;
}

Measured memory_bytes: 256
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int S = Integer.parseInt(str);
        int h = S / 3600;
        S = S % 3600;
        int m = S / 60;
        int s = S % 60;
        System.out.println(h + ":" + m + ":" + s);
        br.close();
    }
}

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

int main() {
  ll n, m;
  cin >> n >> m;

  ll ans = 0;

  if (n == 1 && m == 1) {
    cout << 1 << '\n';
  } else if(n == 1) {
    cout << max(0LL, m - 2) << '\n';
  } else if(m == 1) {
    cout << max(0LL, n - 2) << '\n';
  } else {
    cout << (n - 2) * (m - 2) << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,x,y;
	scanf("%d %d",&a,&b);
	x=a*b;
	y=x%2;
	if(y>=1){
		printf("Odd\n");
	}
	else{
		printf("Even\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#define int long long
using namespace std;
int a, b;
signed main() {
	string s; cin >> s >> s;
	for (int i = 0; i < s.size(); i++)if (s[i] == 'R')a++; else b++;
	cout << (a > b ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    string s;cin >> s;
    int n = s.length();
    LL ans = 0;
    LL c=0;
    bool f=false;
    for (int i = 0; i < n; i++) {
        if(s[i]=='A'){
            if(f){
                c=0;
            }
            c++;
            f=false;
        }
        if(s[i]=='B'){
            if(f) c=0;
            f=true;
        }
        if(s[i]=='C'){
            if(f){
                ans+=c;
            }
            else{
                c=0;
            }
            f=false;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
bf = sum(A_list)

for i in range(N):
    if B_list[i] >= A_list[i]:
        #順番注意
        A_list[i+1] = max(A_list[i] + A_list[i+1] - B_list[i], 0)
        A_list[i] = 0
    else:
        A_list[i] = A_list[i] - B_list[i]  

af = sum(A_list)
print(bf- af)


Measured memory_bytes: 19116
#include <stdio.h>

#define MAX 100

int main(){
  int N,a[MAX],i,j,tmp,count = 0;

  scanf("%d" ,&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d" ,a + i);
  }

  for(i = 0 ; i < N ; i++){
    for(j = N-1 ; j > i ; j--){
      if(a[j] < a[j-1]){
	tmp = a[j];
	a[j] = a[j-1];
	a[j-1] = tmp;
	count++;
      }
    }
  }

  for(i = 0 ; i < N ; i++){
    if(i != N-1){
      printf("%d " ,a[i]);
    }else{
      printf("%d\n%d\n" ,a[i] ,count);
    }
  }

  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main()
{
	char str[100][1000], mark[1000];
	int i, j, turn, count;
	
	for(i = 0; ; i++)
	{
		scanf("%s", str[i]);
		if(strcmp(str[i], "-") == 0) break;
		scanf("%d", &count);
		for(j = 1; j <= count; j++)
		{
			scanf("%d", &turn);
			strcpy(mark, &str[i][turn]);
			strncat(mark, str[i], turn);
			strcpy(str[i], mark);
		}
	}
	
	for(j = 0; j < i; j++)
	{
		printf("%s\n", str[j]);
	}
	
	return 0;
}

Measured memory_bytes: 1040
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

int main(){	
	ll N;
	cin >> N;
	vector<double> A(N);
	rep(i, N) {
		cin >> A[i];
	}
	double sum = 0;
	rep(i,N) {
		sum += 1/A[i];
	}
	printf("%.16f\n", 1 / sum);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll dp[100010];

int main() {

    int n, k;
    cin >> n >> k;

    if (k == 1) cout << 0 << endl;
    else cout << n - k << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string board[50];
  for (int i = 0; i < H; i++) {
    cin >> board[i];
  }
  int dx[8] = {-1,0,1,-1,1,-1,0,1};
  int dy[8] = {1,1,1,0,0,-1,-1,-1};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (board[i][j] == '#') {
        continue;
      }
      int cnt = 0;
      for (int k = 0; k < 8; k++) {
        int y = i + dy[k];
        int x = j + dx[k];
        if ( x >= 0 && x < W && y >= 0 && y < H) {
          if (board[y][x] == '#') cnt++;
        }
      }
      board[i][j] = char(cnt + '0');
    }
  }
  for (int i = 0; i < H; i++) {
    cout << board[i] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG

int main() {
  
  ll N, M;
  cin >> N >> M;
  
  vector<bool> ac(N + 1);
  vector<int> wa(N + 1);
  
  for (ll i=0; i<M;i++){
    ll problrem_id;
    string result;
    cin >> problrem_id >> result;
    if(result == "AC"){
      ac[problrem_id]=1;
    }
    if(result == "WA" && ac[problrem_id] == 0){
      wa[problrem_id]++;
    }
  }

  ll count_ac = 0;
  ll count_wa = 0;
  for(ll i=0; i<N + 1; i++){
    if(ac[i]){
      count_ac++;
      count_wa += wa[i];
    }
  }
  
  cout << count_ac << " " << count_wa << endl;

  return 0;
}


Measured memory_bytes: 3784
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

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

	sort(s.begin(), s.end());
	decltype(s)::iterator r = unique(s.begin(), s.end());
	s.erase(r, s.end());
	int i = 0;
	char ans = 'A';
	for (char c = 'a'; c <= 'z'; c++) {
		if (c != s[i]) {
			ans = c;
			break;
		}
		else {
			i++;
		}
		
	}
	if (ans == 'A') {
		cout << "None" << endl;
	}
	else {
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}


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

    
    int k,a,b;
    cin>>k>>a>>b;
    bool pos = false;
    for(int i=a;i<=b;i++){
        if(i%k==0)pos=1;
    }
    if(pos)cout << "OK\n";
    else cout << "NG\n";


}

Measured memory_bytes: 3620
N, M = list(map(int, input().split()))

H = list(map(int, input().split()))

ans = [1] * N

for i in range(M):
    A, B = list(map(int, input().split()))
    if H[A - 1] > H[B - 1]:
        ans[B - 1] = 0
    elif H[A - 1] < H[B - 1]:
        ans[A - 1] = 0
    else:
        ans[A - 1] = 0
        ans[B - 1] = 0

print(sum(ans))


Measured memory_bytes: 20108
#include <iostream>
#include <string>
#include <map>

using namespace std;

void solve()
{
	map<string, int> Map;
	string str;
	getline(cin, str);
	str += ' ';
	int n = str.size();
	string temp;
	string LongestWord;
	for(int i = 0; i < n; ++i)
	{
		if(str[i] == ' ')
		{
			++Map[temp];
			if(LongestWord.size() < temp.size())
			{
				LongestWord = temp;
			}
			temp.clear();
		}
		else
		{
			temp += str[i];
		}
	}
	int Max = 0;
	string FrequentWord;
	for(map<string, int>::iterator Ite = Map.begin(); Ite != Map.end(); ++Ite)
	{
		if(Max < Ite->second)
		{
			Max = Ite->second;
			FrequentWord = Ite->first;
		}
	}
	cout << FrequentWord << " " << LongestWord << endl;
}

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

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;
 
 
 
int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> vcts(4);
    
    for(int i=0; i<n; i++){
        int x;
        cin>>x;
        vcts[x%4]++;
    }
    if(vcts[2]<=1){
        if(vcts[0]>=n/2) cout<<"Yes";
        else cout<<"No";
    }
    else{
        int rem=n-vcts[2];
        if(vcts[0]>=rem/2+rem%2) cout<<"Yes";
        else cout<<"No";
    }
    
    
    return 0;
    
}

Measured memory_bytes: 256
// 2014/06/16 Tazoe

#include <iostream>
using namespace std;

const int INF = 1000000000;

int main()
{
	while(true){
		int n, m;
		cin >> n >> m;

		if(n==0 && m==0)
			break;

		int C[100][100];
		int T[100][100];
		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				if(i==j){
					C[i][j] = T[i][j] = 0;
				}
				else{
					C[i][j] = T[i][j] = INF;
				}
			}
		}

		for(int i=0; i<n; i++){
			int a, b, c, t;
			cin >> a >> b >> c >> t;

			C[a-1][b-1] = C[b-1][a-1] = c;
			T[a-1][b-1] = T[b-1][a-1] = t;
		}
    for(int k=0;k<m;k++){
      for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
          if(C[i][j] > C[i][k]+C[k][j])
            C[i][j] = C[i][k] + C[k][j];
          if(T[i][j] > T[i][k]+T[k][j])
            T[i][j] = T[i][k] + T[k][j];
        }
      }
    }
    unsigned int k;
    cin >> k;
    for(int i=0;i<k;i++){
      int p,q,r;
      cin >> p >> q;

      cin >> r;

      if(r==0){
        cout << C[p-1][q-1] << endl;
      } else {
        cout << T[p-1][q-1] << endl;
      }
    }
  }

	return 0;
}



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

typedef long long ll;

int main(){

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<ll>A(N);
	vector<ll>sum(N+1, 0);

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

	vector<vector<ll>>dp(N+1, vector<ll>(N+1, 0));

	for(int i=0;i<N;i++)
		sum[i+1] = sum[i]+A[i];

	for(int i=0;i<N;i++)
		dp[i][i] = A[i];

	for(int w=2;w<N+1;w++){
		for(int l=0;l<N;l++){
			int r = l+w;
			if(r > N)break;

			dp[l][r] = LONG_MAX;

			for(int m=l+1;m<r;m++){
				dp[l][r] = min(dp[l][r], dp[l][m] + dp[m][r] + sum[r]-sum[l]);
			}
		}
	}

	cout << dp[0][N]<<endl;
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <cmath>
#include <fstream>
#include <map>

#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define pf push_front

using namespace std;
using ll=long long;
using ld=long double;

const int maxn = 1e6 +2;
const int base = 31;
const int mod = 1e9 +7;

template<class T>
void read(T &x)
{
    register ll c;
    T neg = 1;
    x = (T)0;
    while ((c = getchar()) <= 47 || c >= 58)
        if(c == '-') neg = -1;
    for (; (c > 47 && c < 58); c = getchar())
    {
        x = (x << 3) + (x << 1) + (T)(c - 48);
    }
    x *= neg;
}

int n, k;
ll pre = 0;
map<int, ll> dem;
ll gt[maxn];
int main()
{
    cin >> n >> k;
    ll tong = 0;
    dem.insert({0, 1});
    gt[0] = 0;
    for(int i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        x--;
        pre += x;
        pre %= k;
        gt[i+1] = pre;
        if (i >= k -1)
        {
            dem[gt[i- k + 1]]--;
        }
        if (dem.count(pre))
        {
            tong += dem[pre];
            dem[pre]++;
        }
        else
        {
            dem.insert({pre, 1});
        }
    }
    cout << tong;
}


Measured memory_bytes: 14336
w,h,n = map(int,input().split())
info = [list(map(int,input().split())) for i in range(n)]

yoko = [0,w]
tate = [0,h]

for i in range(n):
  if info [i][2]==1 and yoko[0]<info[i][0]:
    yoko[0]=info[i][0]
  elif info [i][2]==2 and yoko[1]>info[i][0]:
    yoko[1]=info[i][0]
  elif info [i][2]==3 and tate[0]<info[i][1]:
    tate[0]=info[i][1]
  elif info [i][2]==4 and tate[1]>info[i][1]:
    tate[1]=info[i][1]

len_yoko = yoko[1]-yoko[0]
len_tate = tate[1]-tate[0]
if len_yoko<=0 or len_tate<=0:
  print(0)
else:
  print(len_tate*len_yoko)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#define MAX 1000000
using namespace std;

bool prime[MAX+1];

bool hurui(){
  for(int i=0;i<MAX;i++){prime[i]=true;}
  prime[0]=prime[1]=prime[2]=true;

  for(int i=2;i<MAX;i++){
    if(prime[i]){
      for(int j=2*i;j<MAX;j+=i)prime[j]=false;
    }
  }
}


int main(){
  hurui();

  for(;;){
    int n,x;
    cin >> n >> x;
    if(n==0)return 0;

    int kane[n];
    for(int i=0;i<n;i++)
      cin >> kane[i];

    bool dp[x+1];
    for(int i=0;i<=x;i++)dp[i]=false;
    dp[0]=true;

    for(int i=0;i<=x;i++){
      if(dp[i]){
        for(int j=0;j<n;j++){
          if(i+kane[j]<=x)dp[i+kane[j]]=true;
        }
      }
    }

    //cout << "aa";
    for(int i=x;i>=0;i--){
      if(i==0){
        cout << "NA" << endl;
        break;
      }
      if(dp[i]&&prime[i]){
        cout << i << endl;
        break;
      }
    }
  }

}

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

int  main(){
  int n;
  char s[666][666];
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
      cin>>s[i][j];
      s[i+n][j+n]=s[i][j+n]=s[i+n][j]=s[i][j];
    }
  
  int ans=0;
  for(int c=0;c<n;c++){
    int f1=0,f2=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(s[i+c][j]!=s[j+c][i])f1=1;
	if(s[i][j+c]!=s[j][i+c])f2=1;
      }
    }
    if(f1==0)ans+=n-c;
    if(f2==0&&c)ans+=n-c;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
from sys import stdin
import math


def combinations_count(n, r):

    # print(n)
    # print(r)
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


S = int(stdin.readline().rstrip())

if S < 3:
    print(0)
else:
    x = S // 3
    y = S % 3
    count = 0

    for i in range(x):
        j = i + 1
        count = count + combinations_count((S - (3 * j) + 1) + i - 1, i)

    print(count % (10 ** 9 + 7))


Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

ll dp[110][100100];

int main() {

    int n, W;
    cin >> n >> W;
    vector<int> w(n), v(n); 
    REP(i, n) cin >> w[i] >> v[i];

    for(int i = 0; i < 110; i++) {
        for(int j = 0; j < 100100; j++) {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    for(int i = 0; i < n; i++) {
        for(int sum_v = 0; sum_v < 100100; sum_v++) {
            
            if (sum_v - v[i] >= 0) chmin(dp[i+1][sum_v],  dp[i][sum_v-v[i]] + w[i]);
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    ll res = 0;
    for(int sum_v = 0; sum_v < 100100; sum_v++) {
        if (dp[n][sum_v] <= W) res = sum_v;
    }

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

Measured memory_bytes: 86400