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

int n;
int a;
int res = 999999999;

int main(){
  cin >> n;
  rep(i, n){
    cin >> a;
    int tmp = 0;
    while(a % 2 == 0){
      a /= 2;
      tmp++;
    }
    res = min(res, tmp);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    n, *i = map(int, open(0).read().split())
    a = i[:n]
    _ = i[n]
    s = sum(a)

    m = [0] * (10 ** 5 + 1)
    for x in a:
        m[x] += 1

    ans = []
    for b, c in zip(*[iter(i[n + 1:])] * 2):
        m[c] += m[b]
        s += (c - b) * m[b]
        m[b] = 0
        ans.append(s)

    print("\n".join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 44068
# 63


n = int(input())
dp = [[int(x) for x in input().split()] for y in range(n)]
del_l = []
ans = 0

for i in range(n):
    for j in range(i+1,n):
        ans += dp[i][j]

for i in range(n-1):
    for j in range(i+1,n):
        for k in range(n):
            if k in (i,j):
                continue
            if dp[i][j] > dp[i][k] + dp[k][j]:
                print("-1")
                exit()
            elif dp[i][j] == dp[i][k] + dp[k][j]:
                ans -= dp[i][j]
                break

print(ans)

Measured memory_bytes: 74172
#define ll long long int
#include <bits/stdc++.h>
using namespace std;

int main(){
  double D,T,S;
  
  cin >> D >> T >> S;
  
  if ((D / S) <= T)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include<cmath>
#include <ctype.h>
#include <stdlib.h>
#include <vector>
#include <math.h>
#include <stack>
#include <climits>
#define PI 3.14159265
#define ll long long
#define endl '\n'
#define sz(s) (int)(s.size())
#define all(v) v.begin(),v.end()
const int N = 1e6;
using namespace std;
void RUN() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
}
//vector<int>v1(10000), v2(100005), v3(100005);

int main() {
	RUN();

	string s, t;
	cin >> s >> t;
	int mn = INT_MAX;
	for (int i = 0; i < sz(s); i++) {
		for (int j = 0; j < sz(s); j++) {
			if (j - i + 1 == sz(t)) {
				int indx = 0, c = 0;
				for (int k = i; k <= j; k++) {
					if (s[k] != t[indx]) {
						c++;
					}
					indx++;
				}
				if (c < mn) {
					mn = c;
				}
			}
		}
	}
	cout << mn;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(50)

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

int H, W; string S[20];

inline bool inside(int x, int y){
  return x>=0 && x<H && y>=0 && y<W;
}

int bfs(int sx, int sy){
  int dist[20][20];
  REP(i, 20) REP(j, 20) dist[i][j] = -1;
  queue<INTP> que; que.push({sx, sy});
  dist[sx][sy] = 0;
  while(!que.empty()){
    INTP pos = que.front(); que.pop();
    int nowx = pos.first, nowy = pos.second;
    REP(i, 4){
      int nx = nowx + dx[i], ny = nowy + dy[i];
      if(inside(nx, ny) and S[nx][ny] != '#' and dist[nx][ny] == -1){
        dist[nx][ny] = dist[nowx][nowy] + 1;
        que.push({nx, ny});
      }
    }
  }
  int res = -BIG;
  REP(i, H) REP(j, W){
    chmax(res, dist[i][j]);
  }
  return res;
}

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

  cin >> H >> W;
  REP(i, H) cin >> S[i];
  int ans = -BIG;
  REP(i, H) REP(j, W){
    if(S[i][j] == '#') continue;
    chmax(ans, bfs(i, j));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A, B, C ;

cin >> A>> B>>C ;
if ((A==5&& B==5 &&C==7  ) ||(A==5 && B==7&& C==5) ||(A==7 && B==5&& C==5))
   cout << "YES" <<endl;
else
    cout << "NO" <<endl ;


    return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    string s; cin >> s;
    vector<set<int> > adj(n);
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        x--, y--;
        adj[x].insert(y); adj[y].insert(x);
    }
    bool rem[n] = {};
    int cnt[n][2] = {};
    for (int i = 0; i < n; i++) for (int j : adj[i]) cnt[i][s[j] - 'A']++;
    for (int i = 0; i < n; i++) {
        if (rem[i] || (cnt[i][0] > 0 && cnt[i][1] > 0)) continue;
        queue<int> q;
        q.push(i); rem[i] = true;
        while (!q.empty()) {
            int v = q.front(); q.pop();
            for (int u : adj[v]) {
                if(!rem[u] && --cnt[u][s[v]-'A'] == 0) { rem[u] = true; q.push(u); }
            }
        }
    }
    for (int i = 0; i < n; i++) if (!rem[i]) { cout << "Yes\n"; return 0; }
    cout << "No\n";
}


Measured memory_bytes: 28804
#include<bits/stdc++.h>
#define m 1000000007
using namespace std;
vector<int> a;
vector<vector<long long>> dp;
vector<long long> p_sums;
long long solve(int i,int k){
    if(k==0)return 1;
    if(k<0)return 0;
    if(i<0)return 0;
    if(dp[i][k]!=-1)return dp[i][k];
    long long ans = 0LL;
    for(int j=0;j<=a[i];j++){
        ans+=solve(i-1,k-j);
        ans%=m;
    }
    dp[i][k] = ans;
    return dp[i][k];
}
int main(){
    int n,k;
    cin>>n>>k;
    a.resize(n,0);
    dp.resize(n+1,vector<long long>(k+1,0));
    p_sums.resize(k+1,0);
    for(int i=0;i<n;i++)cin>>a[i];
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        p_sums[0] = 1;
        for(int j=1;j<=k;j++)p_sums[j]=(p_sums[j-1]+dp[i-1][j])%m;
        for(int j=0;j<=k;j++){
            if(j-a[i-1]-1<0)dp[i][j]=p_sums[j];
            else dp[i][j] = (p_sums[j]-p_sums[j-a[i-1]-1]+m)%m;
        }
    }
    cout<<dp[n][k]<<"\n";
    return 0;

}

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

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

max_have = 0

for i in range(k + 1):
    if i > n:
        break

    left = v[:i]

    rest = v[i:][::-1]
    rest_n = n - i

    for j in range(k - i + 1):
        if j > rest_n:
            break

        right = rest[:j]

        have = left + right
        have.sort(reverse=True)

        for x in range(k - i - j):
            if not have:
                break

            if have[-1] < 0:
                have.pop()

        if sum(have) > max_have:
            max_have = sum(have)

print(max_have)

Measured memory_bytes: 3064
N = int(input())
h = list(map(int, input().split()))
ans = 0

def func(l):
    global ans
    if type(l) is int:
        ans += l
        return
    if l == []:
        return
    m = min(l)
    ans += m
    l = list(map(lambda x: x-m, l))
    i = l.index(0)
    if i >=  0:
        func(l[:i])
        func(l[i+1:])

func(h)
print(ans)



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

int main()
{
    int N, K;
    std::cin >> N >> K;

    std::vector<long long> H(N);
    for (int i = 0; i < N; i++) {
        std::cin >> H[i];
    }

    std::sort(std::begin(H), std::end(H));

    long long ans = 100000000000000;
    for (int i = 0; i <= N-K; i++) {
        ans = std::min(ans, H[i+K-1] - H[i]);
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007


void solve(void)
{

  string str;
  cin>>str;
  vector<int> vec(26,0);
  for (int i = 0; i < str.size(); i++)
  {
    vec[str[i] - 'a']++;
  }

  int check = 1;

  for (int i = 0; i < 26; i++)
  {
    if(vec[i]%2 == 1) check = 0;
  }

  if(check == 1)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  
  
  
  return;
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    char s[11];
    scanf("%s",s);
    int countls = 0;
    for(int i = 0; i < 11; i++){
        if('A' <= s[i] && s[i] <= 'z'){
            countls++;
        }
    }
    bool checks[countls];
    for(int i = 0; i < countls; i++){
        checks[i] = true;
        if(i == 0){
            checks[i] = false;
        }
    }
    int countC = 0;
    for(int i = 2; i < countls - 1; i++){
        if(s[i] == 'C'){
            countC++;
            checks[i] = false;
        }
    }

    if(s[0] == 'A' && countC == 1){
        for(int i = 1; i < countls; i++){
            if(checks[i]){
                if('a' <= s[i] && s[i] <= 'z'){
                    continue;
                }else{
                    printf("WA\n");
                    
                    return 0;
                }
            }
        }
        printf("AC\n");
    }else{
        printf("WA\n");
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())

past_time = 0
flag = True

data = []

for n in range(N):
    A, B = map(int, input().split())
    data.append([B, A])
    
data.sort()

for dd in data:
    A, B = dd[1], dd[0]
    past_time += A
    if past_time > B:
        flag = False
        break

if flag == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 76580
#057 B
N,M= map(int,input().split())
AB=[[str(j) for j in input().split()] for i in range(N)]
CD=[[str(j) for j in input().split()] for i in range(M)]

for i in range(0, N):
    min_=10**9
    
    ind = 0
    for j in range(0, M):
        if abs(int(AB[i][0])-int(CD[j][0]))+ abs(int(AB[i][1])-int(CD[j][1])) < min_:
            min_=abs(int(AB[i][0])-int(CD[j][0]))+ abs(int(AB[i][1])-int(CD[j][1]))
            ind_ = j
        #print(i,j,min_,ind_+1)
    print(ind_+1)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int a[] = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		System.out.println((int)Math.ceil((double)(N-1)/(K-1)));
	}
}


Measured memory_bytes: 50944
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long
#define mod 1000000007
#define max(p,q)((p)>(q)?(p):(q))
ll powe(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
ll n;
ll a[212345],b[212345];
ll c[212345];
char s[1010];

int main(){
  scanf("%s",s);
  int leng=strlen(s);
  if(s[leng-1]=='s'){
    s[leng]='e';
    s[leng+1]='s';}
  else
    s[leng]='s';

  printf("%s\n",s);

  
  return 0;
}


Measured memory_bytes: 1660
import java.util.*;
class Main{
  static Scanner sc = new Scanner(System.in);
  public static void main(String args[]){
    int A=sc.nextInt(),B=sc.nextInt(),C=sc.nextInt();
    boolean f=false;
    for(int i=1;i<B;i++){
      if((A*i)%B==C){
        f=true;
        break;
      }
    }
    System.out.println(f?"YES":"NO");
  }
}

Measured memory_bytes: 35628
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
#include <iomanip>
#include <unordered_map>

using namespace std;

#define ll long long int


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n,k;
    cin>>n>>k;
    cout<<min( (n%k) , abs(n%k - k) );
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#define ll long long
using namespace std;
int n;
int p[1000];
int a,b;
int c[3];

int main()
{
    cin>>n;
    cin>>a>>b;
    for (int i=0; i<n; ++i)
    {
        cin>>p[i];
        if (p[i]<=a) c[0]++;
        if (p[i]>=a+1 && p[i]<=b) c[1]++;
        if (p[i]>=b+1) c[2]++;
    }
    int m=100000;
    for (int i=0; i<3; ++i)
        if (c[i]<m)
            m=c[i];
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 256
import itertools
import math
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
s = list(itertools.permutations(range(1, n+1)))
ans = 0
for i in range(len(s)):
    sum = 0
    for j in range(n-1):
        sum += math.sqrt(((xy[s[i][j]-1][0] - xy[s[i][j+1]-1][0])**2) + ((xy[s[i][j]-1][1] - xy[s[i][j+1]-1][1])**2))
    ans += sum
print(ans / len(s))

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

int main()
{
    int n;
   cin>>n;
   int ar[n];
   
   for(int i=0;i<n;i++) cin>>ar[i];
   
   reverse(ar,ar+n);

for(int i=0;i<n;i++) cout<<ar[i]<<((i==n-1) ? "\n" : " ");
   

    return 0;
}



Measured memory_bytes: 3092
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
int n,k,a[200005];
long long s=0;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n-k;i++)s+=a[i];
	cout<<s;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

struct PascalTriangle{
    int n;
    vector<vector<int64_t>> table;
    PascalTriangle(int n) : n(n){
        table.resize(n + 1, vector<int64_t>(n + 1, 0));

        table[0][0] = 1;
        for(int i = 0; i < n; ++i){
            table[i + 1][0] = table[i][0];
            table[i + 1][i + 1] = table[i][i];
        }
        for(int i = 0; i < n; ++i){
            for(int j = 1; j < n; ++j){
                if(j >= i + 1)  continue;
                table[i + 1][j] = table[i][j - 1] + table[i][j];
            }
        }
    }

    int64_t get_value(int n, int k){
        if(n < 0 || k < 0 || n < k) return 0;
        return table[n][k];
    }

    void print(){
        for(int i = 0; i <= n; ++i){
            for(int j = 0; j <= n; ++j){
                if(j > i)   continue;
                cerr << table[i][j] << " ";
            }
            cerr << "\n";
        }
    }
};

using ld = long double;

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

    int n, a, b;
    cin >> n >> a >> b;
    vector<ll> v(n);
    vector<ll> sum(n + 1);
    sum[0] = 0;
    for(int i = 0; i < n; ++i)  cin >> v[i];
    sort(v.begin(), v.end(), greater<ll>());
    for(int i = 0; i < n; ++i)  sum[i + 1] = sum[i] + v[i];
    using Pdi = pair<ld, int>;
    vector<Pdi> ave;
    for(int i = a; i <= b; ++i){
        ld foo = (ld)sum[i] / i;
        ave.push_back(Pdi(foo, i));
    }
    Pdi foo = *max_element(ave.begin(), ave.end());
    ld maxave = foo.first;
    int sz = ave.size();
    sort(ave.begin(), ave.end(), greater<Pdi>());
    ll ans = 0;
    PascalTriangle pascal(50);
    for(int i = 0; i < sz; ++i){
        if(ave[i].first != maxave)  break;
        ll cnt = 1;
        map<ll, ll> mp;
        map<ll, ll> mp2;
        int border = ave[i].second;
        for(int j = 0; j < border; ++j){
            ++mp[v[j]];
            ++mp2[v[j]];
        }
        for(int j = border; j < n; ++j){
            if(mp.find(v[j]) == mp.end())   continue;
            ++mp2[v[j]];
        }
        for(auto it : mp){
            cnt *= pascal.get_value(mp2[it.first], it.second);
        }
        ans += cnt;
    }
    cout << fixed << setprecision(6);
    cout << maxave << endl;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

#include <algorithm>

using namespace std;

#define NMAX 100000

static int n, K;
static char s[NMAX + 10];

int main() {
    scanf("%d%d%s", &n, &K, s + 1);
    int m = unique(s + 1, s + n + 1) - s - 1;
    int ans = n - m;
    int c = (m + 1) / 2 - 1;
    ans += 2 * min(c, K);
    if (K > c && !(m & 1)) ans++;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int W,A,B;
    cin>>W>>A>>B;

    if(B+W<A){
        cout<<A-(B+W)<<endl;
    }else if(B<=A+W){
        cout<<0<<endl;
    }else{
        cout<<B-(A+W)<<endl;
    }
}

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

#define ll long long
ll mod=1000000007;

ll power(ll x, ll y) 
{ 
    ll res = 1; 
  
    x = x%mod;

    while (y) 
    { 
        if (y&1) res = ((res%mod)*(x%mod))%mod; 
  
        y>>=1;
        x = ((x%mod)*(x%mod))%mod; 
    } 
    return res; 
}

ll calculateNcr(ll n, ll r){

    if(r==n || r==0) return 1;

    if(n-r<r) r=n-r;

    ll p=1, k=1;

    while (r)
    {
        p=((p%mod)*(n%mod))%mod;
        k=((k%mod)*(r%mod))%mod;

        n--;
        r--;
    }

    k = power(k,mod-2);

    return ((p%mod)*(k%mod))%mod;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n, a, b;
    cin >> n >> a >> b;

    // cout << (power(2,n)-1-(calculateNcr(n,a)+calculateNcr(n,b)))%mod << "\n";

    cout << ((power(2,n)%mod) -1 - (calculateNcr(n,a)%mod) - (calculateNcr(n,b)%mod) + 5*mod)%mod << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N;
  cin >> A;
  
  int M = N % 500;
  if (M > A) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
def main():
    a, b, c = [int(_) for _ in raw_input().split()]
    if a == b == c:
        if a & 1:
            return 0
        return -1

    ans = 0
    while True:
        if a & 1 or b & 1 or c & 1:
            return ans
        a, b, c = (b + c) / 2, (c + a) / 2, (a + b) / 2
        ans += 1

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) begin(a), end(a)
#define pb emplace_back

const ll maxn = 5e5 + 5;
ll n, m;
vector<ll> g[maxn];
ll used[maxn];

void dfs(ll i)
{
    if (used[i] == 2) return;
    if (used[i] == 1)
    {
        cout << "Yes" << endl;
        exit(0);
    }
    used[i] = 1;
    for (ll j : g[i])
    {
        dfs(j);
    }
    used[i] = 2;
}

int main()
{
    cin >> n >> m;
    string s;
    s.reserve(maxn);
    cin >> s;
    while (m--)
    {
        ll a, b;
        cin >> a >> b;
        --a; --b;
        if (s[a] == s[b])
        {
            g[a].pb(b + n);
            g[b].pb(a + n);
        }
        else
        {
            g[a + n].pb(b);
            g[b + n].pb(a);
        }
    }
    for (ll i = 0; i < n; ++i)
    {
        if (!used[i])
        {
            dfs(i);
        }
    }
    cout << "No" << endl;
    return 0;
}


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

int main() {
  
  int n;
  cin >> n;
  
  for ( int i = 1; i < 10; i++){
    if ( n <= i * 111 ){
      cout << i * 111 << endl;
      return 0;
    }
  }
  
  
}



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

const ll mod = 1000000007;

ll powmod(ll x, ll y) {
    ll res = 1;
    for (ll i = 0; i < y; i++) {
        res = res * x % mod;
    }
    return res;
}

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

    ll ans = powmod(10, n) - powmod(9, n) - powmod(9, n) + powmod(8, n);
    ans %= mod;
    ans = (ans + mod) % mod;
    cout << ans << endl;
    
    return 0;
}

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

void strcpyRever(char *s,char *t){	/*	strcpy()tRs[.ver	*/
	int i;
	for(i=0;i<strlen(t);i++)
		s[i]=t[strlen(t)-(1+i)];
	s[i]='\0';
}

char intchar(int S){		/*êÌ®Sð¶R[hÅÎ³¹é*/
	return (char)(S+48);
}

int charint(char *t){		/*¶¨ê®*/
	return (int)*t-48;
}


int main(){
	char ketaA[82],ketaB[82],kekka[82],result[82];		/*'\0'Æ81Úðl¶µÄ*/
	int N,							/*f[^Zbg*/
		S,C,					/*ÀñÁZíÝ½¢ÈàÌðC[WµÄ¢éB*/
		lenghA,lenghB,
		i,j;

	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%81s",ketaA);						/*80ð´¦½çoverflowÈÌÅA81Úª êÎ»êB*/
		scanf("%81s",ketaB);
		lenghA=strlen(ketaA);
		lenghB=strlen(ketaB);

/*		if(strlen(ketaA)>80 || strlen(ketaB)>80){	/*üÍÌiKÅoverflowµÄ¢½çAvZµÄàµÈ­Äà»ê*//*
 *			goto BAD_END;
 *		}
 */				/*()«ª^Å éÀèBñÂÆàfalseÉÈéÆIíè*/
		for(j=0,C=0; (lenghA-(1+j)) >=0 || (lenghB-(1+j)) >=0 ;j++){					/*ºÌÊ©çÁZµÄ¢­B*/
			if(lenghA-(1+j)<0){
				S = charint(&ketaB[lenghB-(1+j)]) + C;
				C = S/10;
				S-= C*10;
				kekka[j]=intchar(S);
			}else if(lenghB-(1+j)<0){
				S = charint(&ketaA[lenghA-(1+j)]) + C;
				C = S/10;
				S-= C*10;
				kekka[j]=intchar(S);
			}else{
				S = charint(&ketaA[lenghA-(1+j)]) + charint(&ketaB[lenghB-(1+j)]) + C;	/*ÅÌJèãªè,CÍ0B	(LXg¾ÆAXL[ÉÈèÜ·)*/
				C = S/10;																/*ÌJèãªèÍ é©ÈB*/
				S-= C*10;								/*SðêÉ*/
				kekka[j]=intchar(S);					/*memo:ãÅtRs[*/
			}
		}
		if(C!=0){			/*Jèãªèª Á½çA*/
			kekka[j]=intchar(C);
			kekka[j+1]='\0';
		}else{
			kekka[j]='\0';
		}
		strcpyRever(result,kekka);					/*memoÌtRs[ÏÝ*/
		
		if(strlen(result)>80){
		/*	BAD_END:				*/
			printf("overflow\n");
		}else{
			printf(result);
			printf("\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

typedef struct{
    int a,b;
}exchange;

int main(void){
    int i,j;
    
    int w,n;
    scanf("%d %d",&w,&n);

    exchange e[n];
    for(i=0;i<n;i++){
        scanf("%d,%d",&e[i].a,&e[i].b);
    }
    
    int x;
    for(i=1;i<=w;i++){
        x=i;
        for(j=n-1;j>=0;j--){
            if(e[j].a==x)x=e[j].b;
            else if(e[j].b==x)x=e[j].a;
        }
        printf("%d\n",x);
    }
    
    return 0;
}



Measured memory_bytes: 2024
#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;



int main() {
	int N,D;
	cin >> N >> D;
	int i;
	
	long long X, Y;
	int poin = 0;
	for (i = 0; i < N; i++) {
		cin >> X >> Y;
		if (sqrt(X * X + Y * Y) <= D)poin++;
	}
	cout << poin << endl;
	return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    /*int h,w;
    while(cin>>h>>w&&h){
        if(h==1&&w==8&&0){
            cout<<4<<" "<<7<<endl;
            continue;
        }
        int s=h*h+w*w;
        int anss=INF;
        int ansh=INF,answ=INF;
        rep(i,1,151){
            rep(j,i+1,151){
                if(s<i*i+j*j && i*i+j*j<anss){
                    anss=i*i+j*j;
                    ansh=i; answ=j;
                }else if(i*i+j*j==anss){
                    if(h<i&&i<ansh){
                        ansh=i; answ=j;
                    }
                }
            }
        }
        cout<<ansh<<" "<<answ<<endl;
    }*/

    int h, w;
    while(cin >> h >> w && h){
        int area = h*h+w*w;
        int resH = 200, resW = 200, resArea = 10000000;
        for(int i=1;i<=150;i++){
            for(int j=i+1;j<=150;j++){
                int newArea = i*i+j*j;
                if(area > newArea || (area == newArea && i <= h)) continue;
                if(newArea < resArea || (newArea == resArea && i < resH)){
                    resH = i;
                    resW = j;
                    resArea = newArea;
                }
            }
        }
        cout << resH << " " << resW << endl;
    }
    return 0;
}



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

int main() {
    int n,d;
    cin >> n >>d;
    int r = 1 + 2*d;
    if (n%r != 0) {
        cout << n/r + 1 << endl;
    }
    else {
        cout << n/r << endl;
    }
}


Measured memory_bytes: 256
N = int(input())
S = [input() for i in range(N)]

def histogram_sorted(data):
    table = []
    prev = data[0]
    c = 1 
    for i in range(1,len(data)):
        if prev == data[i]:
            c=c+1
        else:
            table.append([prev,c])
            prev = data[i]
            c = 1
    table.append([prev,c]) 
    return table

T = []
for i in range(N):
    T.append(S[i])
    
    
print(len(histogram_sorted(sorted(T))))

Measured memory_bytes: 44172
#include<iostream>
using namespace std;
int main()
{
	char a[3];
	cin>>a[0]>>a[1]>>a[2];
	if(a[0]==a[1]&&a[1]==a[2])
		cout<<a[0]<<a[1]<<a[2];
	else
	{
		if(a[0]<a[1])
		{
			if((a[1]-a[0])>1)
				cout<<a[0]-48+1<<a[0]-48+1<<a[0]-48+1;
			else 
				cout<<a[1]<<a[1]<<a[1];
		}
		else
		{
			if(a[0]==a[1])
			{
				if(a[1]<a[2])
				{
					cout<<a[2]<<a[2]<<a[2];
				}
				else
				{
					cout<<a[1]<<a[1]<<a[1];
				}
			}
			else
			{
				cout<<a[0]<<a[0]<<a[0];
			}
		}
	}
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())

if a%2==0 and b%2==0 and c%2==0 and a==b==c:
    print(-1)
else:
    res = 0
    while True:
        if a%2==1 or b%2==1 or c%2==1:
            break
        else:
            a, b, c = b//2+c//2, a//2+c//2, a//2+b//2
            res += 1
    print(res)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(void){
  int ans[10][7] =  {
    {0,1,1,1,1,1,1},  //0
    {0,0,0,0,1,1,0},  //1
    {1,0,1,1,0,1,1},  //2
    {1,0,0,1,1,1,1},  //3
    {1,1,0,0,1,1,0},  //4
    {1,1,0,1,1,0,1},  //5
    {1,1,1,1,1,0,1},  //6
    {0,1,0,0,1,1,1},  //7
    {1,1,1,1,1,1,1},  //8
    {1,1,0,1,1,1,1},  //9
  };
  int n;
  while(cin>>n,n>0){
    int number;
    int now[7]={0,0,0,0,0,0};
    for(int j = 0 ; j < n ; j ++){
      cin>>number;
      for(int i = 0 ; i < 7 ; i ++){
        cout<<(ans[number][i]==now[i]?0:1);
        now[i]=ans[number][i];
      }
      cout<<endl;
    }
  }
}

Measured memory_bytes: 1160
h,w = map(int,input().split())
sl = []
for _ in range(h):
   s = list(input())
   sl.append(s)

G = [[] for i in range(h*w)]
for i in range(h):
    for j in range(w):
        if sl[i][j] == "#":
            continue
        a = i*w + j
        if j != w - 1:
            if sl[i][j+1] != "#":
                b = i*w + j + 1
                G[a].append(b)
        if j != 0:
            if sl[i][j-1] != "#":
                b = i*w + j - 1
                G[a].append(b)
        if i != 0:
            if sl[i-1][j] != "#":
                b = i*w + j - w
                G[a].append(b)
        if i != h - 1:
            if sl[i+1][j] != "#":
                b = i*w + j + w
                G[a].append(b)

# G[v]: 頂点vに隣接する頂点list
# N: 頂点数

ans = 0
from collections import deque
for i in range(h*w):
    if sl[i//w][i%w] == "#":
        continue
    dist = [-1]*(w*h)
    que = deque([i])
    dist[i] = 0
    while que:
        v = que.popleft()
        d = dist[v]
        for p in G[v]:
            if dist[p] > -1:
                continue
            dist[p] = d + 1
            que.append(p)
    ans = max(ans, max(dist))
    
print(ans)

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

const int mod = 1e9 + 7;
int store[100007];
int N;
int cnt[100007];

int main()
{
    cin >> N;

    for (int i = 1; i <= N; i++) scanf("%d", &store[i]);

    bool flg = true;
    for (int i = 1; i <= N; i++) {
        int x = (N+1+store[i]) / 2; ///2p = N+1 +- d [here p = position]
        int y = (N+1-store[i]) / 2;

        if (x > N || y > N) {flg = false; break;}
        cnt[x]++;
        cnt[y]++;
    }

    for (int i = 1; i <= N; i++) if (cnt[i] != 2) {flg = false; break;};

    if (!flg) {printf("0\n"); return 0;}

    ll ans = 1;

    if (N % 2) {
            for (int i = 1; i <= (N-1)/2; i++) {
            ans = (ans * 2) % mod;
        }
    }

    else {
         for (int i = 1; i <= N/2; i++) {
         ans = (ans * 2) % mod;
        }
    }

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


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	arr := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&arr[i])
	}
	var count int
	for i := 0; i < N; i++ {
		min := i
		for j := i; j < N; j++ {
			if arr[j] < arr[min] {
				min = j
			}
		}
		if i != min {
			arr[i], arr[min] = arr[min], arr[i]
			count++
		}
	}
	for i, v := range arr {
		if i != 0 {
			fmt.Print(" ")
		}
		fmt.Print(v)
	}
	fmt.Println()
	fmt.Println(count)
}



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

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b, a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> route(n);
    iota(begin(route), end(route), 0);
    int ans = 0;
    do {
        int count = 1;
        for (int i = 0; i+1 < n; i++) {
            int from = route[i], to = route[i+1];
            if (find(begin(g[from]), end(g[from]), to) == end(g[from])) count = 0;
        }
        ans += count;
    } while (next_permutation(begin(route)+1, end(route)));

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
char s[500000];
deque<int> dq;
int par[500000];
bool dost=true;
stack<int> oper;
void path(int k) {
    if(k==0) return;
    if(par[k]==-1) {
        dost=false;
    }
    oper.push(k-par[k]);
    path(par[k]);
}
int main() {
    scanf("%d %d",&n,&m);
    scanf("%s",s);
    n++;
    dq.push_back(0);
    for(int i=1;i<n;i++) {
        while(dq.size()>0 && i-dq.front()>m) dq.pop_front();
        if(s[i]=='0') {
            if(dq.size()>0) par[i]=dq.front();
            else par[i]=-1;
            dq.push_back(i);
        }
    }
    path(n-1);
    if(dost==false) printf("-1");
    else {
        while(!oper.empty()) {
            printf("%d ",oper.top());
            oper.pop();
        }
    }
    return 0;
}


Measured memory_bytes: 4428
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) {
    cin >> A[i];
  }

  vector<ll> s(N+1); // s[i] .. sum of [0, i)
  rep(i, N) {
    s[i+1] = s[i] + A[i];
  }
  // For Debug
  // rep(i, N+1) {
  //   cout << s[i] << endl;
  // }

  vector<ll> l(N); // the left index of each middle i. the middle in [0, i].
  vector<ll> r(N); // the left index of each middle i. the middle in [i+1, N-1].
  ll left = 0;
  for (int i = 1; i < N-2; ++i) { // calculate l in [1, N-3]
    ll summed = s[i+1]; // The sum of [0, i]
    while ((left <= N) && abs(summed - s[left+1]*2) < abs(summed - s[left]*2)) {
      ++left;
    }
    // Here, left is the index of minimum. summed - s[left] is minimum.
    l[i] = left;
  }
  ll right = 0;
  for (int i = 1; i < N-2; ++i) { // calculate r in [1, N-3]
    if (right < i+1) { right = i+1; } // right must be equal or larger than i+1.
    while ((right <= N) && abs((s[N]-s[right+1]) - (s[right+1]-s[i+1])) < abs((s[N]-s[right]) - (s[right]-s[i+1]))) {
      ++right;
    }
    // Here, right is the index of minimum. s[N] - s[right] is minimum.
    r[i] = right;
  }

  ll ans = INF;
  for (int i = 1; i < N-2; ++i) {
    ll left = l[i];
    ll right = r[i];

    ll l1 = s[left];
    ll l2 = s[i+1] - s[left];
    ll r1 = s[right] - s[i+1];
    ll r2 = s[N] - s[right];
    // For Debug
    // cout << l1 << "," << l2 << "," << r1 << "," << r2 << endl;
    ll min_v = min(min(l1, l2), min(r1, r2));
    ll max_v = max(max(l1, l2), max(r1, r2));
    ans = min(ans, abs(max_v - min_v));
  }

  cout << ans << endl;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
	int X, i = 100, ans = 0;
	scanf("%lld", &X);
	while(i < X){
		i += i / 100;
		ans++;
	}
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

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

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

int a[1100];
int n;

int main() {
	scanf("%d", &n); n = 2*n;
	REP(i,n) scanf("%d", &a[i]);
	sort(a,a+n);
	int b= 0;
	for (int i = 0; i < n; i += 2) {
		b += a[i];
	}
	printf("%d\n", b);
}

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

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

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

	if(s.compare("Sunny") == 0) cout << "Cloudy" << "\n";
	else if(s.compare("Cloudy") == 0) cout << "Rainy" << "\n";
	else cout << "Sunny" << "\n";

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

int main(){
  int n;
  cin>>n;
  pii s;
  s.first = -1;
  s.second = -1;
  REP(i,n){
    pii t;
    cin>>t.second>>t.first;
    t.second = 10000000 - t.second;
    s = max(s,t);
  }
  cout<<(10000000-s.second)<<" "<<s.first<<endl;
  return 0;
}

Measured memory_bytes: 1164
include Math
while (n = gets.to_i) != 0
line = gets.split.map(&:to_f)

ave = line.inject{|sum,i| sum += i}/n

sum = 0
line.each { |n|
sum += ((n - ave) ** 2)
# puts sum
}
puts sta_dev = sqrt(sum / n)
end



Measured memory_bytes: 6936
#include<bits/stdc++.h>
#define LL long long
#define db double

using namespace std;
const int N=500+10,M=100+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
LL f[12],sq[12],an[12][12],nx;
int n,vs[233];
bool ck(int j,int i)
{
	for(int k=0;k<i;++k) if(vs[sq[k]+j]) return 0;
	return 1;
}
int p[12],v[12],cn;
void dfs(int o,LL ns)
{
	if(o>n){nx=max(nx,ns);return;}
	for(int i=1;i<=n;++i)
		if(!v[i])
		{
			v[i]=1,p[o]=i;
			dfs(o+1,ns+an[p[o-1]][p[o]]);
			v[i]=0;
		}
}

int main()
{
	n=rd();
	sq[1]=1,vs[1]=1;
	for(int i=2,j=2;i<=n;++i,++j)
	{
		while(!ck(j,i)) ++j;
		sq[i]=j;
		for(int k=0;k<i;++k) vs[sq[k]+sq[i]]=1;
	}
	memcpy(f,sq,sizeof(sq));
	for(int i=2;i<=n;++i)
	{
		for(int j=1;j<i;++j) an[i][j]=an[j][i]=sq[j];
		nx=0;
		for(int j=1;j<=n;++j) v[j]=1,p[1]=j,dfs(2,0),v[j]=0;
		for(int j=1;j<=n;++j) sq[j]=f[j]*(nx+1);
	}
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n;++j) printf("%lld ",an[i][j]);
		puts("");
	}
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, raw_input().split())
a = [raw_input() for _ in xrange(n)]
b = [raw_input() for _ in xrange(m)]
f = 0
for i in xrange(m):
    if b[i] in a[i]:
        f += 1

if f == m:
    print "Yes"
else:
    print "No"


Measured memory_bytes: 2568
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <utility>
typedef long long lint;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
#define INF 1e18

int A, B, Q, N, M;

signed main()
{
	cin >> N >> M;

	vector<int> K(N);
	vector<vector<int>> A(N);

	rep(i, N)
	{
		cin >> K[i];
		rep(j, K[i])
		{
			int tmp;
			cin >> tmp;
			A[i].push_back(tmp - 1); // 0 から参照したい
		}
	}

	/*
	for (auto a: A) {
		for (auto b: a) {
			cout << b << ", " ;
		}
		cout << endl;
	}
	cout << endl;
	*/

	vector<bool> hoge(M, true);
	// N人分回す
	// foodについて
	for (int food = 0; food < M; food++)
	{
		hoge[food] = true;
		for (int i = 0; i < N; i++)
		{
			// tabemono
			bool tmp = false;
			for (int j = 0; j < K[i]; j++)
			{
				if (A[i][j] == food)
					tmp = true;
			}
			// tmp iの人が好き？
			if (!tmp)
				hoge[food] = false;
		}
	}
	int ans = 0;
	for (auto x : hoge)
	{
		if (x == true)
			ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())

r = dict()
for i in range(1, N + 1):
    ii = str(i)
    a = ii[0]
    b = ii[-1]
    if b == '0':
        continue
    a = int(a)
    b = int(b)
    if (a, b) not in r:
        r[(a, b)] = 0
    r[(a, b)] += 1

result = 0
for i in range(1, 10):
    for j in range(1, 10):
        if (i, j) not in r:
            continue
        if (j, i) not in r:
            continue
        result += r[(i, j)] * r[(j, i)]
print(result)

Measured memory_bytes: 3064
c1 = list(map(int, input().split()))
c2 = list(map(int, input().split()))
c3 = list(map(int, input().split()))

c = [c1, c2, c3]
row = []
p1 = p2 = p3 = 0

for i in c:
    row.append(sum(i))
    p1 += i[0]
    p2 += i[1]
    p3 += i[2]

col = [p1, p2, p3]

con1, con2, con3 = row[0] - row[1], row[0] - row[2], row[1] - row[2]
con4, con5, con6 = col[0] - col[1], col[0] - col[2], col[1] - col[2]

con = [con1, con2, con3, con4, con5, con6]

for j in con:
    if j % 3 != 0:
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
 #define mod 1000000007
 const int N=100005;
 const int inf=1e18;
 
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int l,r;
	cin>>l>>r;
	if(r-l>=2019){
		cout<<0;
		return 0;
	}else{
		int m=100000000000;
		for(int i=l;i<=r;i++){
			for(int j=i+1;j<=r;j++){
				int z=(i*j)%2019;
				if(z<m){
					m=z;
				}
			}
		}
		cout<<m;
	}
	







	
	
return 0;	
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	int y,m,d;
	int sum;

	cin>>n;

	for(int i1=0;i1<n;i1++){
		cin>>y>>m>>d;
		sum=0;
		for(int i1=y+1;i1<1000;i1++){
			if(i1%3==0) sum+=200;
			else sum+=195;
		}

		if(y%3==0){
			for(int i1=m+1;i1<11;i1++){
				sum+=20;
			}
			sum+=(20-d+1);
		}
		else {
			for(int i1=m+1;i1<11;i1++){
				if(i1%2==0) sum+=19;
				else sum+=20;
			}
			if(m%2==0) sum+=(19-d+1);
			else sum+=(20-d+1);
		}

		cout<<sum<<endl;

	}
	return 0;
}

Measured memory_bytes: 1160
/*
 * Author : Sadi
 * Wed 15/07/2020
 * 20:08:42.04
 */
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int r;
    cin >> r;
    cout << r * r << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define rn return
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;

map <string,int> said;
string pword = "BEGIN";
int main(){
    int N; cin >> N;
    rep(i,N){
        string word; cin >> word;
        if (pword != "BEGIN" && pword[pword.size()-1] != word[0]){
            cout << "No" << endl; rn 0;
        }
            
        if (said[word] == 1){
            cout << "No" << endl; rn 0;
        }
        
        said[word] = 1;
        pword = word;
    }
    cout << "Yes";
    rn 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int h,w,n;
int p[SIZE];
set<P> s;

int main(){
  cin >> h >> w >> n;
  rep(i,0,n){
    int x,y;
    cin >> x >> y;
    s.insert(P(x,y));
  }
  int k = h;
  int x=1,y=1;
  p[1] = 1;
  rep(i,0,h){
    if(s.find(P(x+1,y)) != s.end()){
      k = x;
      break;
    }else{
      x++;
    }
    if(s.find(P(x,y+1)) == s.end() && y<w){
      y++;
    }
    p[x] = y;
  }
  for(auto v : s){
    if(v.second <= p[v.first]){
      k = min(k,v.first-1);
    }
  }

  cout << k << endl;


  return 0;
}


Measured memory_bytes: 10368
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 2010;
const ll LL_INF = 1LL << 50;
ll dp[MAX_N][MAX_N][2];
ll N,Z,W;
vector<ll> A;
ll res;
void init(){
  for (int i = 0; i < MAX_N; i++){
    for (int j = 0; j < MAX_N; j++){
      for (int k = 0; k < 2; k++){
        dp[i][j][k] = -1;
      }
    }
  }
}

ll memo(int pos, int idx, bool turn){
  if (pos >= N - 1){
    return abs(A[N - 1] - A[idx]);
  }

  ll &res = dp[pos][idx][turn];
  if (res >= 0){
    return res;
  }

  if (turn){//X
    res = 0;
    for (int i = pos; i < N - 1; i++){
      res = max(res, memo(i + 1, i, !turn));
    }
    res = max(res, abs(A[N - 1] - A[idx]));
  }else{//Y
    res = LL_INF;
    for (int i = pos; i < N - 1; i++){
      res = min(res, memo(i + 1, i, !turn));
    }
    res = min(res, abs(A[N - 1] - A[idx]));
  }
  // cerr << pos << " " << idx << " " << turn << " " << res << endl;
  return res;
}
int main() {
  init();
  cin >> N >> Z >> W;
  A.resize(N);
  for (auto &val : A){
    cin >> val;
  }
  A.push_back(W);
  res = 0;
  ll res = max(res, memo(0, N, true));
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 63488
// 試し割り法による素数判定
function is_prime(n) {
    for (let i = 2; i * i <= n; i++) {
        if (n % i === 0) {
            return false;
        } 
    }
    return n !== 1;  // 1は素数ではないことに注意。
}

// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    
    let answer = 0;
    const n = parseInt(input[0], 10);
    for (let i = 0; i < n; i++) {
        if (is_prime(parseInt(input[i + 1], 10))) {
            answer++;
        }
    }
    console.log(answer);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 17116
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long ll;
#define GG puts("FUCK")
#define N 200050
int n,a[N];
ll ans;
int Abs(int x) {return x>0?x:-x;}
int main() {
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++) {
		scanf("%d",&a[i]); a[i]-=i;
	}
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++) ans+=Abs(a[i]-a[n+1>>1]);
	printf("%lld\n",ans);
}

Measured memory_bytes: 896