akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define def(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(ll i=a;i<n;i++)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        map<ll,ll> ma;
        ll sm = 0;
        ll n; cin>>n;
        vector<ll> a(n);
        FOR(i,0,n) cin>>a[i],ma[a[i]]++, sm+=a[i];
        ll q; cin>>q;
        while(q--){
            ll a,b; cin>>a>>b;
            sm-=ma[a]*a;
            sm+=ma[a]*b;
            ma[b]+=ma[a];
            ma[a]=0;
            cout<<sm<<endl;
        }
    }   
}

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

template<typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template<int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; }
    ModInt& operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; }
    ModInt& operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; }
    ModInt& operator*=(ModInt rhs) { x = (unsigned long long) x * rhs.x % mod; return *this; }
    ModInt& operator/=(ModInt rhs) { x = (unsigned long long) x * rhs.inv().x % mod; return *this; }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) { s << a.x; return s; }
    friend istream& operator>>(istream& s, ModInt<mod>& a) { s >> a.x; return s; }
};

using mint = ModInt<1000000007>;
mint dp[101010][2][2][2];

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

    string s;
    cin >> s;
    int n = s.size();
    dp[0][0][0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2; j++) {
            for (int a = 0; a < 2; a++) {
                for (int b = 0; b < 2; b++) {
                    for (int na = 0; na < 2; na++) {
                        for (int nb = 0; nb < 2; nb++) {
                            if (j) {
                                if (!(na & nb)) {
                                    dp[i + 1][j][na][nb] += dp[i][j][a][b];
                                }
                            } else {
                                if ((na + nb) <= s[i] - '0') {
                                    dp[i + 1][(na + nb) < s[i] - '0'][na][nb] += dp[i][j][a][b];
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    mint ans = 0;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                ans += dp[n][i][j][k];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3712
from collections import Counter
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 2019


s = readline().decode().rstrip()
s = s[::-1]
n = len(s)
d = [0] * (n)
d[0] = int(s[0]) % mod

for i in range(1, n):
    d[i] = (d[i - 1] + int(s[i]) * pow(10, i, mod)) % mod

d = [0] + d

c = Counter(d)
ans = 0
for v in c.values():
    ans += v * (v - 1) // 2
print(ans)

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

string s1;
string s2;

void query1(char a, char b)
{
	cout << s1 << a << endl;
	cout << s2 << b << endl;
	fflush(stdout);
}

void query2(char a, char b)
{
	cout << a << s1 << endl;
	cout << b << s2 << endl;
	fflush(stdout);
}

bool read()
{
	char c; cin >> c;
	if(c == 'T') return true;
	else return false;
}

char dx[4] = {'.', '.', '#', '#'};
char dy[4] = {'.', '#', '.', '#'};

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	bool bac = true;
	while(s1.length() < n && s2.length() < n && bac)
	{
		bac = false;
		for(int i = 0; i < 4; i++)
		{
			query1(dx[i], dy[i]);
			if(read())
			{
				bac = true;
				s1 += dx[i];
				s2 += dy[i];
				break;
			}
		}
	}
	while(s1.length() < n && s2.length() < n)
	{
		for(int i = 0; i < 4; i++)
		{
			query2(dx[i], dy[i]);
			if(read())
			{
				bac = true;
				s1 = dx[i] + s1;
				s2 = dy[i] + s2;
				break;
			}
		}
	}
	cout << s1 << endl << s2 << endl; fflush(stdout);
	string s; cin >> s;
}


Measured memory_bytes: 724
#include <bits/stdc++.h>
using namespace std; 
int main(){
  long long a, b;
  cin >> a >> b;
  long long k = (a + b)/2; 
  if (abs(a-k) != abs(b-k)){
    cout << "IMPOSSIBLE"; 
  } else {
    cout << k; 
  }
}

Measured memory_bytes: 256
/*３つの整数a, b, cを読み込み、
 それらが a < b < cの条件を満たすならば"Yes"を、
 満たさないならば"No"を出力するプログラム*/

#include <stdio.h>

int main(){
    
    int a,b,c;
    
    do{
        scanf("%d %d %d",&a,&b,&c);
    }while(a<0 || a>100 || b<0 || b>100 || c<0 || c>100); /*0 ≤ a, b, c ≤ 100を満たすまで繰り返される*/
    
    if(a<b && b<c){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    
    return 0;
}


Measured memory_bytes: 2104
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))

C = Counter(A)
C = sorted(C.items(), key=lambda x:x[1])

if len(C) <= K:
  print(0)
else:
  print(sum([c[1] for c in C[:len(C)-K]]))

Measured memory_bytes: 39336
def main():
    n = int(input())
    S = list(map(int, input().split()))
    q = int(input())
    T = map(int, input().split())

    ans = 0
    for t in T:
        if binsearch(t, S):
            ans += 1

    print(ans)


def binsearch(x, xs):
    left = 0
    right = len(xs)
    mid = (left + right) // 2

    while left < right:
        if x == xs[mid]:
            return True
        elif x < xs[mid]:
            right = mid
        else:
            left = mid + 1
        mid = (left + right) // 2

    return False

if __name__ == '__main__':
    main()

Measured memory_bytes: 16716
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    int A,B,Q;
    cin >> A >> B >> Q;
    vector<ll> s(A), t(B), x(Q);
    rep(i,A) cin >> s[i];
    rep(i,B) cin >> t[i];
    rep(i,Q) cin >> x[i];
    sort(all(s));
    sort(all(t));
    
    rep(i,Q){
        auto iterS = lower_bound(all(s), x[i]);
        auto iterT = lower_bound(all(t), x[i]);
        
        auto ss = iterS - s.begin();
        auto tt = iterT - t.begin();
        
        ll a,aa,b,bb;
        if(*iterS==x[i]){
            a = x[i],aa = x[i];
        }else if(ss == 0){
            a = s[0],aa = s[0];
        }else if(ss == A){
            a = s.back(),aa = s.back();
        }else{
            a = s[ss];
            aa = s[ss-1];
        }
        
        
        if(*iterT==x[i]){
            b = x[i],bb = x[i];
        }else if(tt == 0){
            b = t[0],bb = t[0];
        }else if(tt == B){
            b = t.back(),bb = t.back();
        }else{
            b = t[tt];
            bb = t[tt-1];
        }
        
        ll ans = 500000000000;
        ans = min(ans, abs(x[i]-a)+abs(a-b));
        ans = min(ans, abs(x[i]-a)+abs(a-bb));
        ans = min(ans, abs(x[i]-aa)+abs(aa-b));
        ans = min(ans, abs(x[i]-aa)+abs(aa-bb));
        
        ans = min(ans, abs(x[i]-b)+abs(b-a));
        ans = min(ans, abs(x[i]-b)+abs(b-aa));
        ans = min(ans, abs(x[i]-bb)+abs(bb-a));
        ans = min(ans, abs(x[i]-bb)+abs(bb-aa));
        
        //cout << a << " " << aa << " " << b << " " << bb << endl;;
        
        cout << ans << endl;
    }
    
    
    
    return 0;
}



Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
typedef pair<string, string> P;

int main(int argc, char *argv[])
{
  int n, b;
  long a[200000];
  long sum=0;
  cin >> n;
  for(long i=0;i<n;i++){
    cin >> a[i];
    a[i]-=(i+1);
  }
  sort(a, a+n);
  if(n%2==0){
    if(abs(a[n/2-1])>abs(a[n/2])){
      b=a[n/2-1];
    }else{
      b=a[n/2];
    }
  }else{
    b=a[n/2];
  }
  for(int i=0;i<n;i++){
    a[i]-=b;
    a[i]=abs(a[i]);
    sum+=a[i];
  }

  cout << sum << endl;
  return 0;
}


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

int g[700][700];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b; a--, b--
      ;
    g[a][b] = g[b][a] = 1;
  }
  int did[700] = {};
  int sz[700] = {};
  int szc[700] = {};
  int col[700] = {};
  for(int i = 0; i < n; i++) {
    if(did[i]) continue;
    col[i] = 1;
    queue<int> q;
    q.emplace(i);
    while(q.size()) {
      int j = q.front();q.pop();
      if(did[j]) continue;
      did[j] = 1;
      if(col[j] == 1) szc[i]++; else sz[i]++;
      for(int k = 0; k < n; k++) if(k != j && !g[k][j]) {
        if(col[k] != 0 && col[k] != 3 - col[j]) {
          cout << -1 << endl;
          return 0;
        }
        col[k] = 3 - col[j];
        q.push(k);
      }
    }
  }
  int dp[777] = {};
  dp[0] = 1;
  ll ans = 0;
  vector<int> v;
  for(int i = 0; i < n; i++) if(szc[i]) {
    ans += min(szc[i], sz[i]);
    v.emplace_back(abs(szc[i]-sz[i]));
  }
  for(int i = 0; i < v.size(); i++) {
    for(int j = 700; j >= 0; j--) {
      if(j - v[i] >= 0) dp[j] |= dp[j - v[i]];
    }
  }
  ll res = 1e18;
  for(int i = 0; i <= 700; i++) if(dp[i]) {
    ll a = ans + i;
    ll b = n - a;
    res = min(res, a * (a-1) / 2 + b * (b-1)/2);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2304
s=input()
n=len(s)
ans = 'No'

if s==s[::-1]:
    if s[0:(n-1)//2] == ''.join(list(reversed(s[0:(n-1)//2]))):
        if s[(n+1)//2:n] == s[0:(n-1)//2]:
            ans= 'Yes'

print(ans)

Measured memory_bytes: 3060
#include <ctype.h>
#include <stdio.h>

int main(void) {
	char ch;
	
	while(scanf("%c", &ch) && ch != '\n' ){
		if(islower(ch))
			ch = toupper(ch);
		else if(isupper(ch))
			ch = tolower(ch);
		printf("%c", ch);
	}
	putchar('\n');
	
	return 0;
}



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

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	int four=0,two=0,one=0;
	
	for(int i=0;i<n;i++){
		if(a[i]%4==0)	four++;
		else if(a[i]%2==0)	two++;
		else one++;
	}
	
	if(two>0){
		if(four>=one) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else{
		if(four>=(one-1)) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	

	return 0;
}

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

int main() {
  int k;
  cin >> k;
  if( k%2 == 0 ){
    cout << (k/2)*(k/2) << endl;
  }else{
    cout << ( (k-1)/2 )*( (k-1)/2 + 1 ) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc109/tasks/abc109_d
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
inline int read() {
    int tmp = 0;
    char c = getchar(), f = 1;
    for (; c < '0' || '9' < c; c = getchar())
        if (c == '-')
            f = -1;
    for (; '0' <= c && c <= '9'; c = getchar())
        tmp = (tmp << 3) + (tmp << 1) + c - '0';
    return tmp * f;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    h = read(), w = read();
    vector<vector<int>> v(h, vector<int>(w));
    REP(i, h) REP(j, w) v[i][j] = read();
    bool coin = false;
    vector<pii> ans, tmp;
    REP(i, h) REP(j, w) {
        int k = (i % 2 == 0 ? j : (w - j - 1));
        if (coin) {
            // ボールの合計が奇数の場合、ボールを持ったまま終わることを考慮
            tmp.push_back({i + 1, k + 1});
        }
        if (v[i][k] % 2 == 1) {
            if (coin) {
                coin = false;
                // 出力は1-indexed
                for (auto &x : tmp) {
                    ans.push_back(x);
                }
                tmp.clear();
            } else {
                coin = true;
            }
        }
        if (coin) {
            tmp.push_back({i + 1, k + 1});
        }
    }
    cout << ans.size() / 2 << "\n";
    REP(i, ans.size()) {
        cout << ans[i].first << " " << ans[i].second << (i % 2 ? "\n" : " ");
    }

    return 0;
}


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

long long MOD = 1000 * 1000 * 1000 + 7;

long long p(long long a, long long b) {
	if (b == 0) return 1;
	if (b == 1) return a;
	long long ha = p(a, b/2);
	if (b % 2 == 0) return (ha * ha) % MOD;
	return (((ha * ha) % MOD) * a) % MOD;
}

int main() {
	
	long long n;
	cin >> n;
	long long ar[n];
	for (int i=0; i<n; i++) cin >> ar[i];
	
	sort(ar, ar+n);
	reverse(ar, ar+n);
	
	long long x = p(2, 2*n-2);
	long long s = 0;
	for (int i=1; i<=n; i++) {
		s += (i + 1) * (ar[i-1]);
		s %= MOD;
	}
	
	cout << (x * s) % MOD << endl;
	
	
}


Measured memory_bytes: 1792
n=int(input())
mod=10**9+7
memo=[{} for _ in range(n+1)]
def ok(last4):
    for i in range(4):
        t=list(last4)
        if i>=1:
            t[i-1],t[i]=t[i],t[i-1]
        if "".join(t).count("AGC")>=1:
            return False
    return True

def dfs(cur,last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur==n:
        return 1
    ret=0
    for c in "ACGT":
        if ok(last3+c):
            ret=(ret+dfs(cur+1,last3[1:]+c))%mod
    memo[cur][last3]=ret
    return ret
dfs(0,"TTT")
print(memo[0]["TTT"])


Measured memory_bytes: 48220
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll> 
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0;cin>>n;
  lvector A(n,0),B(n,0),C(n,0);
  rep(i,n) cin>>A[i];rep(i,n) cin>>B[i];rep(i,n) cin>>C[i];
  sort(ALL(A));sort(ALL(B));sort(ALL(C));
  ll apos=0,cpos=0;
  for(ll b:B) {
    apos=lower_bound(ALL(A),b)-A.begin()-1;
    cpos=n-(lower_bound(ALL(C),b+1)-C.begin());
    if(apos>=0) ans+=(apos+1)*cpos;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;

int main()
{
    int n,m;
    cin >> n >> m;
    int ans = 0;
    vector<int> k(m);
    vector<vector<int> > s(m,vector<int>(n,0));
    for(int i = 0; i < m; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            int t;
            cin >> t;
            t--;
            s[i][t] = 1;
        }
    }
    vector<int> p(m);
    for(int i = 0; i < m; i++) cin >> p[i];
    for(int i = 0; i < (1 << n); i++){
        vector<int> temp(m,0);
        for(int j = 0; j < n; j++){
            if((1 << j) & i){
                for(int k = 0; k < m; k++){
                    if(s[k][j] == 1) temp[k]++;
                }
            }
        }
        bool f = true;
        for(int j = 0; j < m; j++){
            if(temp[j] % 2 == p[j]) continue;
            else f = false;
        }
        if(f) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))

relative_distance = []
relative_distance.append(A[0] + K - A[-1])

for i in range(len(A)-1):
    relative_distance.append(A[i+1] - A[i])

print(sum(relative_distance) - max(relative_distance))

Measured memory_bytes: 26000
#include <stdio.h>
#include <string.h>

int main(void){
  int i,j,k,l;
  char str[10000];
  int count_j,count_i;

  while(1){
    scanf("%s",str);
    if(feof(stdin))break;

    count_j=0;
    count_i=0;

    l=strlen(str);

    for(i=0;i<l-2;i++){
      if(str[i]=='J'){
	if(str[i+1]=='O'){
	  if(str[i+2]=='I'){
	    count_j++;
	  }
	}
      }
      if(str[i]=='I'){
	if(str[i+1]=='O'){
	  if(str[i+2]=='I'){
	    count_i++;
	  }
	}
      }
    }
    printf("%d\n",count_j);
    printf("%d\n",count_i);
  }
  return(0);
}

Measured memory_bytes: 556
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    
    int w, h;
    w = abs(sx - tx);
    h = abs(sy - ty);
    
    for (int i = 0; i < w; i++) {
        cout << "R";
    }
    for (int i = 0; i < h; i++) {
        cout << "U";
    }
    for (int i = 0; i < w; i++) {
        cout << "L";
    }
    for (int i = 0; i < h; i++) {
        cout << "D";
    }
    
    cout << "D";
    
    for (int i = 0; i < w + 1; i++) {
        cout << "R";
    }
    for (int i = 0; i < h + 1; i++) {
        cout << "U";
    }
    
    cout << "L";
    
    cout << "U";
    
    for (int i = 0; i < w + 1; i++) {
        cout << "L";
    }
    for (int i = 0; i < h + 1; i++) {
        cout << "D";
    }
    
    cout << "R" << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long ;
int main()
{
    int n,x,t,ans=1;
    cin>>n>>x>>t;
    while(n>x*ans){
        ans++;
    }
    cout<<t*ans;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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;}

#define rep(i,n) for(int i=0;i<(n);i++)

int main(){
    int A[3];
    cin>>A[0]>>A[1]>>A[2];
    sort(A,A+3);
    int a=A[2]-A[1],b=A[1]-A[0];
    cout<<a+b<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#define fr first
#define sc second
#define MP make_pair
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
using namespace std;

lli gcd(lli a, lli b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
lli cg(lli n) {
	return n ^ (n >> 1);
}
lli SUM(lli a)
{
	return (a * (a + 1) / 2);
}
bool CAN(int x, int y, int n, int m)
{
	if (x >= 0 && y >= 0 && x < n && y < m)
	{
		return true;
	}
	return false;
}
double her(double x1, double y1, double x2, double y2)
{
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
string strsum(string a, string b)
{
	int p = 0;
	string c;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	if (b.length() < a.length())
	{
		for (int i = b.length(); i < a.length(); i++)
		{
			b += "0";
		}
	}
	else
	{
		for (int i = a.length(); i < b.length(); i++)
		{
			a += "0";
		}
	}

	a += "0", b += "0";
	for (int i = 0; i < a.length(); i++)
	{
		c += (a[i] - '0' + b[i] - '0' + p) % 10 + '0';
		p = (a[i] + b[i] - '0' - '0' + p) / 10;
	}
	if (c[c.length() - 1] == '0') c.erase(c.length() - 1, 1);
	reverse(c.begin(), c.end());
	return c;
}
string strmin(string a, string b)
{
	if (a.length() > b.length()) return b;
	if (b.length() > a.length()) return a;
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] > b[i]) return b;
		if (b[i] > a[i]) return a;
	}
	return a;
}

char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };



const int N = 1e6 + 30;
const lli mod = 1000000007;

int a;
string s;
int main()
{
	fastio;
	cin >> a >> s;
	if (a < 3200)
	{
		cout << "red";

	}
	else
		cout << s;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
using namespace std;
const int MAX = 1e5 + 10;
const ll MOD = 1e9 + 7;
int N, M, K, Q;

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

int main()
{
	int i, j, k;
	ll x, y;
	scanf("%lld %lld", &x, &y);
	ll g = gcd(x, y);
	if (y / g == 1) {
		printf("-1");
		return 0;
	}
	printf("%lld", x);

}

Measured memory_bytes: 256
A, B, H, M = map(int, input().split())

# 時針: 12時間720分で360度 1分で0.5度
# 分針: 60分で360度 1分で6度
theta = abs(((0.5 * (H * 60 + M)) - (6 * M)) % 360)
if theta > 180:
  theta = 360 - theta
#print(theta)
import math
C = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta / 180 * math.pi))
print(C)

Measured memory_bytes: 9492
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

vector<int> color;
vector<int64_t> cc = {0,0};//oと1の数を記録するvector
bool is_biparticle = true;

void dfs(Graph &G, int v , int cor = 0){
  color[v] = cor;
  cc[cor]++;
  for(auto next_v : G[v]){//ここが原因
    if(color[next_v] != -1){//隣接頂点が既に塗られてた場合は
      if(color[next_v] == cor) is_biparticle = false;//同色ならfalse
      else continue;//異色なら次の探査へ
    }

    else{//隣接頂点が未探査だった場合は
      dfs(G, next_v, 1-cor);//next_vの色を変えて探査する
    }
  }
}

int main(){
  int64_t n,m;cin >> n >> m;
  Graph G(n);
  for (size_t i = 0; i < m; i++) {
    int a,b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  color.assign(n,-1);
  dfs(G, 0);
  if(is_biparticle) std::cout << cc[0]*cc[1] - m << '\n';
  else std::cout << n*(n-1)/2 - m << '\n';
}


Measured memory_bytes: 6656
N = gets.to_i
a = gets.chomp.split(" ").map(&:to_i);

ans = 0
for i in 1..a.length - 1 do
  if a[i] == a[i - 1] 
    a[i] = a.max + 1
    ans += 1 
  end
end

print(ans)


Measured memory_bytes: 1788
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <limits>
#include <math.h>
#include <string>
#include <map>

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (int i = 0; i < h; ++i) cin >> a[i];

  int pr = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (a[i][j] == '#') {
	if (j < pr) {
	  puts("Impossible");
	  return 0;
	}
      pr = j;
      }
    }
  }
  puts("Possible");
  return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    String s = sc.next();
    char[] c = new char[n + 1];
    for (int i = 0; i < n; i++) {
      c[i + 1] = s.charAt(i);
    }
    long ans = 0;
    int[] rCountCache = new int[4009];
    int[] gCountCache = new int[4009];
    int[] bCountCache = new int[4009];
    for (int i = c.length - 1; i >= 0; i--) {
      int r = c[i] == 'R' ? 1 : 0;
      int g = c[i] == 'G' ? 1 : 0;
      int b = c[i] == 'B' ? 1 : 0;
      rCountCache[i] += rCountCache[i + 1] + r;
      gCountCache[i] += gCountCache[i + 1] + g;
      bCountCache[i] += bCountCache[i + 1] + b;
    }
    for (int i = 1; i < c.length; i++) {
      for (int j = i + 1; j < c.length; j++) {
        if (c[i] == c[j]) {
          continue;
        }
        int exceptionIndex = j + j - i;
        if ((c[i] == 'R' && c[j] == 'G') || (c[i] == 'G' && c[j] == 'R')) {
          ans += bCountCache[j + 1];
          if (exceptionIndex <= n && c[exceptionIndex] == 'B') {
            ans--;
          }
        } else if ((c[i] == 'R' && c[j] == 'B') || (c[i] == 'B' && c[j] == 'R')) {
          ans += gCountCache[j + 1];
          if (exceptionIndex <= n && c[exceptionIndex] == 'G') {
            ans--;
          }
        } else if ((c[i] == 'G' && c[j] == 'B') || (c[i] == 'B' && c[j] == 'G')) {
          ans += rCountCache[j + 1];
          if (exceptionIndex <= n && c[exceptionIndex] == 'R') {
            ans--;
          }
        } else {
          throw new IllegalArgumentException();
        }
      }
    }
    pw.println(ans);
  }
}


Measured memory_bytes: 36852
using System;
using System.Linq;

namespace ABC134_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var ND = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = ND[0];
            var D = ND[1];

            var f = N % (1 + 2 * D) == 0;
            Console.WriteLine(f ? N / (1 + 2 * D) : N / (1 + 2 * D) + 1);
        }
    }
}


Measured memory_bytes: 13268
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var S = Scanner.Scan<string>();
            var ok = true;
            for (int i = 0, j = S.Length - 1; i < j && ok; i++, j--)
            {
                if(S[i] != S[j]) ok = false;
            }
            for (int i = 0, j = (S.Length - 1) / 2 - 1; i < j && ok; i++, j--)
            {
                if(S[i] != S[j]) ok = false;
            }
            Console.WriteLine(ok ? "Yes" : "No");
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 26676
n, C = map(int, input().split())
d = []
for i in range(C):
    d.append(list(map(int, input().split())))
c = []
for i in range(n):
    c.append(list(map(int, input().split())))
c0 = {}
c1 = {}
c2 = {}
for i in range(0, n * 2 - 1, 3):
    for j in range(max(0, i - n + 1), min(n, i + 1)):
        c0.setdefault(c[j][i - j], 0)
        c0[c[j][i - j]] += 1
for i in range(1, n * 2 - 1, 3):
    for j in range(max(0, i - n + 1), min(n, i + 1)):
        c1.setdefault(c[j][i - j], 0)
        c1[c[j][i - j]] += 1
for i in range(2, n * 2 - 1, 3):
    for j in range(max(0, i - n + 1), min(n, i + 1)):
        c2.setdefault(c[j][i - j], 0)
        c2[c[j][i - j]] += 1
D = []
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i == j or j == k or k == i:
                continue
            temp = 0
            for p, q in c0.items():
                temp += d[p - 1][i] * q
            for p, q in c1.items():
                temp += d[p - 1][j] * q
            for p, q in c2.items():
                temp += d[p - 1][k] * q
            D.append(temp)
print(min(D))

Measured memory_bytes: 12744
#!/usr/bin/env python
# -*- coding: utf-8 -*-

BASE = 2019


def find_min_val(L, R):
    if R - L > 3000:
        return 0

    res = 2018
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            res = min(res, (i * j) % 2019)

    return res


def main():
    L, R = map(int, input().split())

    ans = find_min_val(L, R)
    print(ans)


main()


Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
string s;
int main()
{
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5])
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 1000 + 5;
const ll INF = 1e17 + 7 , mod = 1e9 + 7;
const double eps = 1e-9 , PI = acos(-1);


int n , m;

char a[N][N];

void solve(int testCase){

    scanf("%d %d" , &n , &m);

    for(int i = 0 ; i < n ; i ++){
            scanf("%s" , a[i]);
    }

    vector < vl > dp(n+1 , vl(m+1 , 0));
    dp[1][1] = 1;

    for(int i = 1 ; i <= n ; i ++){
            for(int j = 1 ; j <= m ; j ++){
                    if(a[i-1][j-1] == '#')continue;

                    dp[i][j] += dp[i-1][j] + dp[i][j-1];
                    dp[i][j] %= mod;
            }
    }

    printf("%lld\n" , dp[n][m]);
}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 9088
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////
const int magic = 998244353;

void add (int & a, int b) {
    a += b;
    if (a >= magic)
        a -= magic;
}

int mul (int a, int b) {
    return (int64)a * b % magic;
}

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

    int N, S;
    cin >> N >> S;
    vector<int> A(N);

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

    vector<vector<vector<int>>> dp(N + 1, vector<vector<int>>(S + 1, vector<int>(3)));

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

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= S; j++) {
            add(dp[i+1][j][0], dp[i][j][0]); 

            add(dp[i+1][j][1], dp[i][j][0]);            
            add(dp[i+1][j][1], dp[i][j][1]);

            int nj = j + A[i];
            if (nj <= S) {
                add(dp[i+1][nj][1], dp[i][j][0]);
                add(dp[i+1][nj][1], dp[i][j][1]);
            }

            add(dp[i+1][j][2], dp[i][j][0]);
            add(dp[i+1][j][2], dp[i][j][1]);
            add(dp[i+1][j][2], dp[i][j][2]);

            if (nj <= S) {
                add(dp[i+1][nj][2], dp[i][j][0]);
                add(dp[i+1][nj][2], dp[i][j][1]);
            }

        }
    }

    cout << dp[N][S][2] << "\n";

    return 0;
}


Measured memory_bytes: 493056
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <cstring>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F0(i,n) for (int i = 0; i < n; i++)
#define F1(i,n) for (int i = 1; i <= n; i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define SZ(x) ((int)x.size())
const double eps = 1e-10;
const int inf = 1000000009;
int i, j, k, m, n, l;
int ans;
vector<int> adj[2005];

int rec(int i, int par, int h) {
	if (h < 0) return 0;
	int ret = 1;
	for (int j : adj[i]) if (j != par) ret += rec(j, i, h - 1);
	return ret;
}

int main() {
	//freopen("x.in", "r", stdin);
	cin >> n >> k;
	F0(u, n - 1) {
		cin >> i >> j;
		adj[i].push_back(j);
		adj[j].push_back(i);
	}

	F1(i, n) {
		int s = 1, maxd = 0;
		for (int j : adj[i]) {
			int x = rec(j, i, k / 2 - 1);
			s += x;
			if (k % 2 == 1) {
				int y = rec(j, i, k / 2);
				maxd = max(maxd, y - x);
			}
		}
		ans = max(ans, s + maxd);
		//cout << i << " " << s << endl;
	}
	cout << n - ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <iomanip>
#include <cassert>
#include <numeric>
using namespace std;
 
#define ff first
#define ss second
#define pb push_back 
 
using LL = long long int;
using VL = vector<LL>;
using VI = vector<int>;
using VVL = vector<VL>;
using PLL = pair<LL,LL>;
using PII = pair<int ,int>;
 
#ifdef DEBUG
void _print()
{
  cout << endl;
}
template<typename T, typename... Args >
void _print(const T first_elem, const Args... args)
{
  cout << first_elem << " ";
  _print(args...);
}
#else
void _print()
{
}
template<typename T, typename... Args >
void _print(const T first_elem, const Args... args)
{
}
#endif
 
 
// NOTE: Please dont implement _print() as function in your program. It is reserved
// for debug purpose.

int main()
{
    ios::sync_with_stdio(false);
    LL t = 1;
    while (t--) {
        LL n;
        cin >> n;
        VL a(n);
        map<LL,LL> m;
        LL sum  =0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            sum += a[i];
            m[a[i]]++;
        }

        LL q;
        cin >> q;
        while (q--) {
            LL c,v;
            cin >> c >> v;
            cout << sum  - c * m[c] + v * m[c] << endl;
            sum = sum  - c * m[c] + v * m[c];
            m[v] += m[c];
            m[c] = 0;
        }


    }
    return 0;
    
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    string s;
    cin >> s;
    rep(i,0,4) cout << s[i];
    cout << " ";
    rep(i,4,12) cout << s[i];
    cout << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
import Control.Monad
dist a b c d = abs(a-c)+abs(b-d)
 
main = do
  [n,m] <- map read.words <$> getLine 
  ab <- replicateM n $ map read . words <$> getLine :: IO [[Int]]
  cd <- replicateM m $ map read . words <$> getLine :: IO [[Int]]
  mapM (print.snd.minimum) $ (map (\[a,b]->map (\ ([c,d],i)->(dist a b c d,i)) $ zip cd [1..])) $ ab 

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

using i64 = int64_t;

int main(){
    i64 n, k, s;
    cin >> n >> k >> s;
    for(int i=0;i<n;++i){
        if(i)cout << " ";
        if(i<k)cout << s;
        else cout << (s == 1000000000 ? 1 : s+1);
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1280
import java.util.*;
import java.io.*;
public class Main {
	public static void main(String args[]){
		Scanner sc=new Scanner(new InputStreamReader(System.in));
		int seconds=sc.nextInt();
		sc.close();
		int h=seconds/3600;
		int m=(seconds-h*3600)/60;
		int s=seconds-h*3600-m*60;
		System.out.println(h+":"+m+":"+s);
	}
}

Measured memory_bytes: 26120
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let v = read_vec::<usize>();
    println!("{}",if v[0] <= v[1] { v[0] } else  { v[0] - 1 });
}


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

typedef pair <int, int> PII;
typedef vector <PII> VPII;
typedef long long LL;
const int NONE = -1;
int n;
VPII P;
LL memo[101][101];

LL solve( int l, int r ) {
    if ( memo[l][r] != NONE ) return memo[l][r];
    if ( l == r ) return memo[l][r] = 0;
    LL res = 1LL<<60;
    for ( int i = l; i < r; ++ i ) {
        res = min( res, solve( l, i ) + solve( i + 1, r ) + P[l].first * P[i].second * P[i+1].first * P[r].second );
    }
    return memo[l][r] = res;
}

int main() {
    cin >> n;
    P = VPII(n);
    for ( int i = 0; i < n; ++ i ) {
        cin >> P[i].first >> P[i].second;
    }
    for ( int i = 0; i < n; ++ i ) {
        for ( int j = 0; j < n; ++ j ) {
            memo[i][j] = NONE;
        }
    }
    cout << solve( 0, n - 1 ) << endl;
    return 0;
}

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

int main() {
	int A[2], K;
	cin >> A[0] >> A[1] >> K;
	for (int i = 0;i < K;++ i) {
		A[i & 1] >>= 1;
		A[!(i & 1)] += A[i & 1];
	}
	cout << A[0] << " " << A[1];
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

実際にシミュレーションするだけ。O(K)
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;
ll INF = 2e9;

int main()
{
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n),f(n);
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> f[i];
	sort(ALL(a));
	sort(ALL(f), greater<ll>());
	ll l = -1;
	ll r = 1e12;
	while (l + 1 < r)
	{
		ll c = l + (r - l) / 2;
		bool ok = [&]()
		{
			ll sum = 0;
			rep(i, n) sum += max(a[i] - c / f[i] , (ll)0);
			return sum <= k;
		}();
		if (ok) r = c;
		else l = c;
	}
	co(l + 1);
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int c, n;
vector<VI> p;
bool check(int y, int x) {
    bool ret = true;
    if (p[y][x] != p[n - y - 1][x])ret = false;
    if (p[y][x] != p[n - y - 1][n - x - 1])ret = false;
    if (p[y][x] != p[y][n - x - 1])ret = false;
    return ret;
}

int main() {
    init();

    cin >> c >> n;
    p.resize(n, VI(n));
    string in;
    FOR(y, 0, n) {
        cin >> in;
        FOR(x, 0, n)p[y][x] = in[x] - '0';
    }

    int num = 0;
    FOR(y, 0, n / 2)FOR(x, 0, n / 2)if (check(y, x))num++;

    int ans = (num == n * n / 4 ? 1 : 0);
    int d, dy, dx;
    FOR(i, 0, c - 1) {
        cin >> d;
        FOR(j, 0, d) {
            cin >> dy >> dx;
            dy--, dx--;
            if (check(dy, dx))num--;

            p[dy][dx] = 1 - p[dy][dx];
            if (check(dy, dx))num++;
        }
        if (num == n * n / 4)ans++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 6788
#include <stdio.h>

void qsort(int a[], int first, int last){
    if(first >= last)return;
    int pv = a[first], head = first+1, end = last, buf;
    while(1){
        while(head < end && pv <= a[head]) head++;
        while(head < end && pv >= a[end]) end--;
        if(head == end)break;
        buf = a[head];
        a[head] = a[end];
        a[end] = buf;
    }
    if(a[head]<pv) head--;
    a[first] = a[head];
    a[head] = pv;
    qsort(a,first,head-1);
    qsort(a,head+1,last);
    return;
}

int main(void){
    int i, n, ans=0;
    scanf("%d",&n);
    int a[n];
    for(i=0; i<n; i++) scanf("%d",&a[i]);
    qsort(a,0,n-1);
    for(i=0; i<n;){
        ans += a[i++];
        if(i < n)ans -= a[i++];
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  ll x;
  while (cin >> x) {
    ll res = 2 * (x / 11);
    ll rem = x % 11;
    if (rem != 0) {
      if (rem <= 6) {
        res += 1;
      } else {
        res += 2;
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//struct cmp {bool operator()(const pair<int, char> &a, const pair<int, char> &b) {if (a.first == b.first) {return a.second > b.second;} else {return a.first > b.first;}}};
#include<bits/stdc++.h>
#define endl "\n"
#define _  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define min_heap priority_queue <int, vector<int>, greater<int> >
#define max_heap priority_queue <int>
#define ll long long
//#define int long long
#define MOD 1000000007#define deb3(x,y,z) cout << #x << "=" << x << "\t"<<#y<<"="<<y<< "\t"<<#z<<"="<<z<<endl;
#define DEBUG cout<<"Hello1\n";
#define deb(x) cout << #x << " " << x << endl;
#define deb2(x,y) cout << #x << "=" << x << "\t\t"<<#y<<"="<<y<<endl;
#define deb3(x,y,z) cout << #x << "=" << x << "\t"<<#y<<"="<<y<< "\t"<<#z<<"="<<z<<endl;
#define all(v) (v).begin(),(v).end()
using namespace std;

void solve() {
	string s;
	cin >> s;

	set<char> ms;
	if (s[0] == s[1]) {
		cout << 1 << " " << 2;
		return;
	}
	ms.insert(s[0]);
	ms.insert(s[1]);
	for (int i = 2; i < s.size(); i++) {
		ms.insert(s[i]);
		if (ms.size() < 3) {
			cout << i - 1 << " " << i + 1;
			return;
		} else {
			ms.erase(s[i - 2]);
		}
	}

	cout << -1 << " " << -1;
}

int32_t main() {
	_

	solve();
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int l = a + b;
  	int r = c + d;
    if (l > r) cout << "Left" << endl;
    else if (l == r) cout << "Balanced" << endl;
    else cout << "Right" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<queue>
#define mem(x) memset(x,0,sizeof(x)) 
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define prt(x) printf("%d\n",x)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi=acos(-1); 
const double eps=1e-2;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<string,string> pcc;
int main()
{
	int x;
	cin>>x;
	int l[10],r[10];
	for(int i=1;i<=8;i++)
	{
		l[i]=1800-(i-1)*200;
		r[i]=1999-(i-1)*200;
		if(x>=l[i]&&x<=r[i])
		{
			cout<<i<<endl;
			break;
		}
	//	cout<<l[i]<<' '<<r[i]<<endl;
	}
}

Measured memory_bytes: 3632
//writer: Sakura
//name: Pyramid

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

int n;
struct Node{
	int x,y,h;
}a[105];

bool cmp(Node p,Node q){
	return p.h<q.h;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].h);
	}
	sort(a+1,a+1+n,cmp);
	int hl,hn;
	for(int i=0;i<=100;i++){//横坐标
		for(int j=0;j<=100;j++){//纵坐标
			int flag=0;
			int ansh=abs(i-a[1].x)+abs(j-a[1].y)+a[1].h;
			for(int k=1;k<=n;k++){
				if(abs(i-a[k].x)+abs(j-a[k].y)+a[k].h<=ansh){
					ansh=abs(i-a[k].x)+abs(j-a[k].y)+a[k].h;
				}
			}
			for(int k=1;k<=n;k++){
				if(a[k].h!=max(ansh-abs(i-a[k].x)-abs(j-a[k].y),0)){
					flag=1;break;
				}
			}
			if(flag==0){
				printf("%d %d %d\n",i,j,ansh);
				exit(0);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
pair<int, int> red[200], blue[200];
int ans;
bool taken[200];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &blue[i].first, &blue[i].second);
	}
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &red[i].first, &red[i].second);
	}
	sort(red, red+n);
	sort(blue, blue+n);
	for (int i = 0; i < n; i++)
	{
		pair<int, int> works = { -1, -1 };
		for (int j = 0; j < n; j++)
		{
		//	printf("hi\n");
			if (blue[j].first < red[i].first && blue[j].second < red[i].second && !taken[j])
			{
				works = max(works, { blue[j].second, j });
			}
		}
		if (works.first != -1)
		{
			taken[works.second] = 1;
			ans++;
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
def larger(x, y):
	if x > y: return x
	return y

N, W = map(int, input().split())
dp = []
for i in range(0, N+1):
	lst = []
	for j in range(0, W+1):
		lst.append(-1)
	dp.append(lst)
dp[0][W] = 0
for i in range(0, N):
	v, w = map(int, input().split())
	for j in range(0, W+1):
		if dp[i][j] != -1:
			dp[i+1][j] = larger(dp[i][j], dp[i+1][j])
			if j - w >= 0:
				dp[i+1][j-w] = larger(dp[i][j]+v, dp[i+1][j-w])
max = 0
for i in range(0, W+1):
	if max < dp[N][i]: max = dp[N][i]
print(max)


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int l, r;
    l = a + b;
    r = c + d;
    if (l > r) {
        cout << "Left" << endl;
    } else if (l == r) {
        cout << "Balanced" << endl;
    } else if (l < r) {
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a;
    for(int i =0;i<n;i++){
        int x;
        cin >> x;
        a.push_back(x);
    }
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for(int i = 2;i<a.size();i++){
        dp[i] = min(dp[i-2] + abs(a[i] - a[i-2]), dp[i-1] + abs(a[i] - a[i-1]));
    }
    cout << dp[n-1];
}









Measured memory_bytes: 1144