akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 200000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int N;
int A[MAX_N];
ll S[MAX_N + 1];

int main(void)
{
  cin >> N;
  REP(i, N) cin >> A[i];

  S[0] = 0;
  REP(i, N) S[i + 1] = S[i] + A[i];

  int l = 1, r = 3;
  ll ans = INT_MAX;
  for (int i = 2; i < N - 1; i++) {
    while (abs(S[i] - 2 * S[l]) > abs(S[i] - 2 * S[l + 1])) l++;
    while (abs(S[N] - S[i] - 2 * (S[r] - S[i])) >
           abs(S[N] - S[i] - 2 * (S[r + 1] - S[i])))
      r++;
    ll w = S[l], x = S[i] - S[l], y = S[r] - S[i], z = S[N] - S[r];
    ans = min(ans, max({w, x, y, z}) - min({w, x, y, z}));
  }

  cout << ans << endl;

  return 0;
}


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

#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e5 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}



int main()
{
  ios::sync_with_stdio(false);
  int a,b,c,x,y;
  cin >> x >> y >> a >> b >> c;
  vector<ll>p(a), q(b), r(c);

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

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

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

  sort(all(p), greater<ll>());
  sort(all(q), greater<ll>());
  sort(all(r), greater<ll>());

  while(p.size() > x)
    p.pop_back();


  while(q.size() > y)
    q.pop_back();


  vector<ll>d(all(p));

  d.insert(d.end(), all(q));
  d.insert(d.end(), all(r));


  sort(d.begin(), d.end(), greater<ll>());

  ll ans = accumulate(d.begin(), d.begin() + x + y , 0LL);

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 6592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
#define all(a) a.begin(), a.end()
#define mp(a, b) make_pair(a, b)

int INF = 100100100;
int MOD = 10e7+9;

int main(){
    int N;
    cin >> N;
    vector<ll> div(N+1, 0);

    rep(i, 1, N+1){
        for (int j = i; j <= N; j += i){
            ++div[j];
        }
    }
    ll ans = 0;
    rep(i, 1, N+1){
        ans += i*div[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 81384
function Main(input) {
	input = input.trim();
  input = input.split("\n");
  var output = 0;
  for(var i = 0; i < 3; i++){
    var tmp1 = input[0].slice(i,i+1);
    var tmp2 = input[1].slice(i,i+1);
    if(tmp1 == tmp2){
       output++
       }
  }
  console.log(output);
}

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


Measured memory_bytes: 22964
using System;

namespace ABC172
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            int ans = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != t[i])
                {
                    ans += 1;
                }
            }
            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }
}

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

int main()
{
  int ans;
  cin >> ans;

  while( 1 ) {
    char c;
    cin >> c;
    if( c == '=' ) {
      cout << ans << endl;
      break;
    } else {
      int n;
      cin >> n;
      if( c == '+' ) ans += n;
      if( c == '-' ) ans -= n;
      if( c == '*' ) ans *= n;
      if( c == '/' ) ans /= n;
    }
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define forn for(int i=0;i<n;i++)
#define pb push_back
#define pr pair<int,int>
#define mp make_pair
#define ll long long int
const int mod=1e9+7;
int main(){
    ll n;
    cin>>n;
    double l=(double)n/3;
    //printf("%.12f\n",l);
    l=l*l*l;
    printf("%.12f",l); 
}

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

class Program
{
    static readonly char Wall = 'X';
    int H, W, N;
    string[] grid;

    void Solve()
    {
        H = read.NextInt(); W = read.NextInt(); N = read.NextInt();
        grid = new string[H];
        int[] si = new int[N + 1];
        int[] sj = new int[N + 1];
        char[] cs = new[] { 'S' }.Concat(Enumerable.Range(1, N).Select(i => (char)('0' + i))).ToArray();

        for (int i = 0; i < H; i++)
        {
            grid[i] = Console.ReadLine();
            for (int ci = 0; ci <= N; ci++)
            {
                int j = grid[i].IndexOf(cs[ci]);
                if (j >= 0) { si[ci] = i; sj[ci] = j; }
            }
        }
        int ans = Enumerable.Range(0, N).Sum(i => BFS(si[i], sj[i], si[i + 1], si[i + 1], cs[i + 1]));
        Console.WriteLine(ans);
    }

    int BFS(int si, int sj, int gi, int gj, char goalCh)
    {
        Queue<int> que = new Queue<int>();
        que.Enqueue(si); que.Enqueue(sj);
        int?[,] dist = new int?[H, W];
        dist[si, sj] = 0;

        while (que.Count > 0)
        {
            int i = que.Dequeue(), j = que.Dequeue();
            if (grid[i][j] == goalCh) return dist[i, j].Value;
            for (int d = 0; d < di.Length; d++)
            {
                int ni = i + di[d], nj = j + dj[d];
                if (IsInside(ni, nj) && grid[ni][nj] != Wall && !dist[ni, nj].HasValue)
                {
                    dist[ni, nj] = dist[i, j] + 1;
                    que.Enqueue(ni); que.Enqueue(nj);
                }
            }
        }
        return int.MaxValue;
    }

    static readonly int[] di = { 0, 0, -1, 1 };
    static readonly int[] dj = { -1, 1, 0, 0 };
    bool IsInside(int i, int j)
    {
        return i >= 0 && i < H && j >= 0 && j < W;
    }

    static void Main() { new Program().Solve(); }
    static Read read = new Read();
    class Read
    {
        private Queue<string> que = new Queue<string>();
        public string Next() { return Dequeue(); }
        public int NextInt() { return int.Parse(Dequeue()); }
        public long NextLong() { return long.Parse(Dequeue()); }
        public double NextDouble() { return double.Parse(Dequeue()); }
        public int[] IntArray() { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); }
        public string[] StringArray(int N) { return Enumerable.Range(0, N).Select(i => Console.ReadLine()).ToArray(); }
        private string Dequeue()
        {
            if (que.Count == 0) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s);
            return que.Dequeue();
        }
    }
}

Measured memory_bytes: 16164
N = int(input())
a = list(map(int, input().split()))
cost_odd = 0
cost_even = 0

if a.count(a[0]) == N:
    print(0)
    exit()

num_even = sum(a) // N + 1
num_odd = sum(a) // N

for i in range(N):
    cost_even += (a[i] - num_even)**2
    cost_odd +=  (a[i] - num_odd)**2

print(min(cost_odd, cost_even))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

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

    private static int[] insertionSort(int[] a) {
        printArray(a);
        for (int i = 1; i < a.length; i++) {
            int target = a[i];
            int j = i - 1;
            while (j >= 0 && a[j] > target) {
                a[j + 1] = a[j];
                j--;
            }
            a[j + 1] = target;
            printArray(a);
        }
        return a;
    }

    private static void printArray(int[] array) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            sb.append(array[i]);
            if (i != array.length - 1) {
                sb.append(" ");
            }
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 28448
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long sum = 0;
		for(int i = 1; i <= N; i++) {
			if(i%3!=0 && i%5!=0) 
				sum+=i;
		}
		System.out.println(sum);
	}

}


Measured memory_bytes: 35728
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { int X;
  cin >> X;
  if(X<1200){
    puts("ABC");
  }else{
    puts("ARC");
  }
}

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

typedef long long int64;

int main() {
    int64 x, k, d;

    scanf("%lld %lld %lld", &x, &k, &d);
    x = std::abs(x);
    if(x / d >= k) 
        printf("%lld\n", x - k * d);
    else {
        k -= x / d;
        x -= x / d * d;
        if(k & 1)
            printf("%lld\n", std::abs(x - d));
        else
            printf("%lld\n", x);
    }
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    ll n;   cin >> n;
    vector<vector<ll>> a(n, vector<ll>(3));
    REP(i, n) REP(j, 3) cin >> a[i][j];
    vector<vector<ll>> dp(n, vector<ll>(3, 0));
    REP(i, 3)   dp[0][i] = a[0][i];
    FOR(i, 1, n){
        REP(j, 3){
            REP(k, 3){
                if(j==k) continue;
                dp[i][j] = max(dp[i-1][k]+a[i][j], dp[i][j]);
            }
        }
    }
    ll res=0;
    REP(i, 3) res = max(res, dp[n-1][i]);
    cout << res << endl;
}


Measured memory_bytes: 14016
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll N;
int main(){
  cin>>N;
  vector<ll>A(N);
  for(ll i=0;i<N;i++)
    cin>>A[i];
ll ans=0;
  for(ll i=0;i<N-1;i++){
  ans+=(A[i]/2);
    ll a=A[i]-2*(A[i]/2);
    if(a==1 && 1<=A[i+1]){
      A[i+1]--;ans++;
    }
  }ans+=(A[N-1]/2);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4048
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-10;
double EQ(double a,double b){
	return abs(a-b)<EPS;
}
const int INF=1000000000;
int dp1[2][1000001];
int dp2[2][1000001];
void solve(){
	vector<int> nums;
	for(int i=1;;i++){
		int a=i*(i+1)*(i+2)/6;
		nums.push_back(a);
		if(a>1000000)break;
	}
	int n=nums.size()-1;
	for(int i=n;i>=0;i--){
		int cur=i%2;
		int nxt=(i+1)%2;
		for(int j=0;j<=1000000;j++){
			int res=INF;
			if(i==n){
				if(j==0)res=0;
			}
			else{
				if(j-nums[i]>=0)
					res=min(res,dp1[cur][j-nums[i]]+1);
				res=min(res,dp1[nxt][j]);
			}
			dp1[cur][j]=res;
		}
	}
	nums.clear();
	for(int i=1;;i++){
		int a=i*(i+1)*(i+2)/6;
		if(a%2==1)
			nums.push_back(a);
		if(a>1000000)break;
	}
	n=nums.size()-1;
	for(int i=n;i>=0;i--){
		int cur=i%2;
		int nxt=(i+1)%2;
		for(int j=0;j<=1000000;j++){
			int res=INF;
			if(i==n){
				if(j==0)res=0;
			}
			else{
				if(j-nums[i]>=0)
					res=min(res,dp2[cur][j-nums[i]]+1);
				res=min(res,dp2[nxt][j]);
			}
			dp2[cur][j]=res;
		}
	}
	int in;
	while(cin>>in&&in){
		cout<<dp1[0][in]<<" "<<dp2[0][in]<<endl;
	}
}


int main(){
	solve();

}

Measured memory_bytes: 16000
#include <stdio.h>

int main(void)
{
	typedef char String[1024];

	int N;
	String cap;
	scanf("%d\n",&N);
	scanf("%s", cap);
	int R=0;
        int B=0;	
	
	for(int i=0;i<N;i++){
		if('R' == cap[i]){
		R = R + 1;
		}
		else if('B' == cap[i])
		{
		B = B + 1; 
		}	
	}

	if(R > N/2){
	printf("Yes\n");
	}else{
	printf("No\n");
	}


	return 0;
	
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> dist(H*W, vector<int>(H*W, 99999));
    for (int i = 0; i < H*W; i++) dist[i][i] = 0;
    vector<string> grid(H);
    for (int i = 0; i < H; i++) cin >> grid[i];
    for (int i = 0; i < H-1; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == '.' && grid[i+1][j] == '.') {
                dist[i*W+j][(i+1)*W+j] = 1;
                dist[(i+1)*W+j][i*W+j] = 1;
            }
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W-1; j++) {
            if (grid[i][j] == '.' && grid[i][j+1] == '.') {
                dist[i*W+j][i*W+j+1] = 1;
                dist[i*W+j+1][i*W+j] = 1;
            }
        }
    }
    for (int k = 0; k < H*W; k++) {
        for (int i = 0; i < H*W; i++) {
            for (int j = 0; j < H*W; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < H*W; i++) {
        for (int j = i+1; j < H*W; j++) {
            if (dist[i][j] < 10000) ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	float ans;
	if(n%2==0)
	{
		ans=0.500000000;
	}
	if(n%2==1)
	{
		ans=float(n/2 +1)/float(n);
	}
	cout << fixed << setprecision(10) <<ans ; 
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#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) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int dp[301][301];

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


	int N, M;
	cin >> N >> M;

	int xm[301][4], xM[301][4];
	rep1(i, N) {
		xm[i][1] = 1000;
		xm[i][2] = 1000;
		xM[i][2] = -1;
		xM[i][3] = -1;
	}
	rep(i, M) {
		int l, r, x;
		cin >> l >> r >> x;
		chmin(xm[r][x], l);
		chmax(xM[r][x], l);
	}

	const int mod = 1e9 + 7;
	dp[0][0] = 1;
	rep1(i, N) {
		for (int j = i - 1; j >= 0; j--) for (int k = i - 1; k >= j; k--) {
			int tmp = dp[j][k];
			dp[j][k] = 0;
			int jj = j;
			int kk = k;
			int OK = 1;
			if (xm[i][1] < kk) OK = 0;
			if (xm[i][2] < jj) OK = 0;
			if (xM[i][2] >= kk) OK = 0;
			if (xM[i][3] >= jj) OK = 0;
			if (OK) dp[jj][kk] = tmp;
			jj = j;
			kk = i;
			OK = 1;
			if (xm[i][1] < kk) OK = 0;
			if (xm[i][2] < jj) OK = 0;
			if (xM[i][2] >= kk) OK = 0;
			if (xM[i][3] >= jj) OK = 0;
			if (OK) {
				dp[jj][kk] += tmp;
				if (dp[jj][kk] >= mod) dp[jj][kk] -= mod;
			}
			jj = k;
			kk = i;
			OK = 1;
			if (xm[i][1] < kk) OK = 0;
			if (xm[i][2] < jj) OK = 0;
			if (xM[i][2] >= kk) OK = 0;
			if (xM[i][3] >= jj) OK = 0;
			if (OK) {
				dp[jj][kk] += tmp;
				if (dp[jj][kk] >= mod) dp[jj][kk] -= mod;
			}
		}
	}

	ll kotae = 0;
	rep(j, N + 1) rep(k, N + 1) {
		kotae += dp[j][k];
	}
	co(kotae% mod);

	Would you please return 0;
}

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

int main() {
  long long int X;
  cin >> X;
  long long int year=0;
  long long int x=100;
  while(x<X){
    x = (long long int)(x*1.01);
    year++;
  }

  cout << year << endl;

}


Measured memory_bytes: 3620
N,A,B = map(int,input().split())
S = input()

a = b = 0
ans = []
for c in S:
    if c=='a':
        if a+b < A+B:
            a += 1
            ans.append('Yes')
        else:
            ans.append('No')
    elif c=='b':
        if a+b < A+B and b < B:
            b += 1
            ans.append('Yes')
        else:
            ans.append('No')
    else:
        ans.append('No')
print(*ans, sep='\n')

Measured memory_bytes: 6344
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n
# a, b = list(map(int, input().split()))
# s = input()


s = set()
N = int(input())
for i in range(N):
    S = input()
    s.add(S)

print(len(s))


Measured memory_bytes: 31208
fn main() {
    proconio::input! {
        n: usize,
    }
    // a * b + c = n
    // n - c = a * b
    // a * b が n より小さい組み合わせの数
    let mut count = 0usize;
    for a in 1..n {
        let mut b = n / a;
        if a * b == n {
            b -= 1;
        }
        count += b;
    }
    println!("{}", count);
}


Measured memory_bytes: 2164
#include <iostream>
#include <map>
#include <string>
#include <vector>

int main()
{
    int N;
    scanf("%d", &N);
    std::string hoge;
    std::cin >> hoge;
    std::vector<std::map<char, int>> dict;
    int ans;

    std::map<char, int> tmp_map;
    for (int i = 0; i < N; i++) {
        auto tmp_char = static_cast<char>(hoge[i]);
        if (tmp_map.find(tmp_char) == tmp_map.end()) {
            tmp_map[tmp_char] = 1;
        } else {
            tmp_map[tmp_char] += 1;
        }
        dict.push_back(tmp_map);
    }

    for (int i = 0; i < N; i++) {
        int num = 0;
        auto tmp_map2 = dict.at(i);
        for (auto itr = tmp_map2.begin(); itr != tmp_map2.end(); ++itr) {
            //            std::cout << "key = " << itr->first << ", val = " << itr->second << "\n";  // 値を表示
            if (tmp_map[itr->first] != itr->second) {
                num += 1;
            }
        }
        if (ans < num) {
            ans = num;
        }
    }
    printf("%d\n", ans);


    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <deque>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

constexpr int dx[] = { 1, 0, -1, 0 };
constexpr int dy[] = { 0, 1, 0, -1 };

int main() {
  int N;
  std::cin >> N;
  std::vector<int> R(N * N), C(N * N);
  for (int i: range(0, N * N)) {
    int x;
    std::cin >> x;
    --x;
    R[i] = x / N;
    C[i] = x % N;
  }
  std::vector<std::vector<int>> dist(N, std::vector<int>(N));
  for (int i: range(0, N)) {
    for (int j: range(0, N)) {
      dist[i][j] = std::min({ i, j, N - i - 1, N - j - 1 });
    }
  }
  std::vector<std::vector<bool>> exist(N, std::vector<bool>(N, true));
  int ans = 0;
  for (int k: range(0, N * N)) {
    ans += dist[R[k]][C[k]];
    exist[R[k]][C[k]] = false;
    std::deque<std::pair<int, int>> que;
    que.emplace_back(R[k], C[k]);
    while (!que.empty()) {
      auto [x, y] = que.front();
      que.pop_front();
      if (exist[x][y]) {
        for (int l: range(0, 4)) {
          int nx = x + dx[l];
          int ny = y + dy[l];
          if (nx >= 0 && ny >= 0 && nx < N && ny < N && chmin(dist[nx][ny], dist[x][y] + 1)) {
            que.emplace_back(nx, ny);
          }
        }
      }
      else {
        for (int l: range(0, 4)) {
          int nx = x + dx[l];
          int ny = y + dy[l];
          if (nx >= 0 && ny >= 0 && nx < N && ny < N && chmin(dist[nx][ny], dist[x][y])) {
            que.emplace_front(nx, ny);
          }
        }
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}


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

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

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve()
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int n = vs[0];
			int x = vs[1];
			int[] m = new int[n];
			for (int i = 0; i < n; i++) {
				m[i] = int.Parse(Console.ReadLine());
			}
			Array.Sort(m);
			int ans = 0;
			for (int i = 0; i < n; i++) {
				if (x < m[i]) {
					break;
				}
				x -= m[i];
				ans++;
			}
			ans += x / m[0];
			Console.WriteLine(ans);

		}
	}
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  string s;
  cin >> s;

  char now = s[0];
  ll count = 1;
  ll ans = 0;
  REP(i, 3){
    if(now != s[i+1]){
      ans = max(ans, count);
      now = s[i+1];
      count = 1;
    }
    else
      count++;
  }
  ans = max(ans, count);

  if(ans >= 3)
  cout << "Yes" << endl;
  else
    cout << "No" << endl;

}


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

typedef unsigned long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define int ll
#define MOD 1000000007
#define maxn 1000010


int num[maxn], A[maxn], N;


int32_t main()
{
    cin>>N;
    FOR(i,1,N) cin>>A[i];
    
    FOR(i,0,maxn-1) num[i] = 0;
    
	FOR(i,1,N){
		int x = A[i];
		if (x % 2 == 0) num[2]++;
		while (x % 2 == 0) x /= 2;
		
		for (int i=3;i<=sqrt(x); i += 2){
			if (x % i == 0) num[i]++;
			while (x % i == 0) x /= i;
		}
		if (x > 2) num[x]++;
	}

	
 
    bool pairwise = 1;
    FOR(i,2,maxn - 1) if (num[i] > 1){
		pairwise = 0;
	}
    
    if (pairwise){
		cout<<"pairwise coprime";
		return 0;
	}
	
	int cur = A[1];
	FOR(i,2,N) cur = __gcd(cur, A[i]);
	
	if (cur == 1) cout<<"setwise coprime";
	else cout << "not coprime";
}


Measured memory_bytes: 19264
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	int p[100000] = {0}, m[100000] = { 0 };
	char S[100000][3];
	bool t[100000] = {false};

	for (int i = 0; i < M; i++) {
		scanf("%d%s", &p[i], S[i]);
	}

	int E = 0, C = 0;
	for (int j = 0; j < M; j++) {
		if (t[p[j]-1] == false) {
			if (strcmp(S[j],"WA")==0) {
				m[p[j]-1]++;
			}
			else{
				C++;
				t[p[j]-1] = true;
				E = E + m[p[j] - 1];
			}
		}
	}

	printf("%d %d",C,E);
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	int n, s[200000] = {}, result = 0,lamp=1;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
	}
	for (int i = 1; i <= 2*n; i++) {
		lamp = s[lamp];
		result++;
		if (lamp == 2) { cout << result; return 0; }
	}
	cout << -1;
}


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

int main(){
  int N,Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> l(Q),r(Q);
  for(int i = 0; i < Q; i++){
    cin >> l[i] >> r[i];
  }

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

  for(int i = 1; i < S.size(); i++){
    if(S[i-1] == 'A' && S[i] == 'C'){
      sum[i+1] = sum[i] + 1;
    }
    else{
      sum[i+1] = sum[i];
    }
  }
  int ans;
  for(int i = 0; i < Q; i++){
    ans = sum[r[i]] - sum[l[i]];
    cout << ans << endl;
  }
}

Measured memory_bytes: 2176
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
using namespace std;
#define inf 0x3f3f3f
typedef long long ll;
const int maxn = 1e2+5;
int m,n,a[maxn];
bool cmp(int a, int b){
	return a > b;
}
int main(){
	cin >> n >> m;
	int sum = 0;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
		sum += a[i];
	}
	double num = sum / 4.0 / m;
	sort(a+1,a+n+1,cmp);
	int cnt = 0;
	for(int i = 1;i <= n;i++){
		if(a[i] >= num)
			cnt++;
		else
			break;
	}
	if(cnt >= m)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 888
from collections import Counter
N = int(input())
MOD = 10**9+7
A = list(map(int,input().split()))
c = Counter(A)
flag = True
if N%2 == 0:
    for i in range(1,int(N/2),2):
        if c[i] != 2:
            flag = False
else:
    if c[0] != 1:flag = False
    for i in range(2,int(N/2),2):
        if c[i] != 2:
            flag = False





if flag:print(2**(N//2)%MOD)
else:print(0)

Measured memory_bytes: 14948
/*
Case i: x
*/

int main(void) {
    int a;
    int i = 1;
    
    while (1) {
        scanf("%d", &a);
        if (a == 0) {
            break;
        }
        
        printf("Case %d: %d\n", i++, a);
    }
    
    return 0;
}


Measured memory_bytes: 2016
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int F[2100010];

int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}
int cnt[100010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    REP(i, 1, K) cnt[i] = power(K/i, N);
    //REP(i, 1, K) cout << i << " " << cnt[i] << endl;
    RREP(i, K, 2) {
        int num = i;
        for(int j = 1; j * j <= i; j++) {
            if(i % j != 0) continue;
            if(j != 1)
            cnt[num/j] = (cnt[num/j] - cnt[i] + mod) % mod;
            if(num/j != j)
                cnt[j] = (cnt[j] - cnt[i] + mod) % mod;
        }
        //if(num != i && i % num == 0) cnt[num] = (cnt[num] - cnt[i] + mod) % mod;
        //if(num != 1 )cnt[1] = (cnt[1] - cnt[i] + mod) % mod;
    }
   
    //REP(i, 1, K) cout << i << " " << cnt[i] << endl;
    int ans = 0;
    REP(i, 1, K) ans = (ans + Mul(cnt[i], i)) % mod;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4396
#include <iostream>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

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

int n, x[100001];

int main() {
	int i;
	
	cin >> n >> x[0];
	rep(i, n) cin >> x[i + 1];
	n++;
	sort(x, x + n);
	
	int g = x[1] - x[0];
	rep(i, n - 2) {
		g = gcd(g, x[i + 2] - x[i + 1]);
	}
	cout << g << endl;
	return 0;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))

i = 0
while i < n - 1:
    if a[i] <= 0:
        a[i] *= -1
        a[i+1] *= -1
    i += 1

s_a = sorted(a)

if s_a[0] < 0 and abs(s_a[0]) > s_a[1]:
    s_a[0] *= -1
    s_a[1] *= -1
    print(sum(s_a))
else:
    print(sum(s_a))

Measured memory_bytes: 14412
// 2014/11/08 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	int N;
	cin >> N;

	string S;
	cin >> S;

	int DP[1001][8];
	DP[0][4] = 1;		// 0日目をJ君のみとする
	DP[0][0] = DP[0][1] = DP[0][2] = DP[0][3] = DP[0][5] = DP[0][6] = DP[0][7] = 0;

	for(int i=1; i<=N; i++){
		DP[i][0] = 0;
		DP[i][1] = DP[i-1][1]           +DP[i-1][3]           +DP[i-1][5]           +DP[i-1][7];
		DP[i][2] =            DP[i-1][2]+DP[i-1][3]                      +DP[i-1][6]+DP[i-1][7];
		DP[i][3] = DP[i-1][1]+DP[i-1][2]+DP[i-1][3]           +DP[i-1][5]+DP[i-1][6]+DP[i-1][7];
		DP[i][4] =                                  DP[i-1][4]+DP[i-1][5]+DP[i-1][6]+DP[i-1][7];
		DP[i][5] = DP[i-1][1]           +DP[i-1][3]+DP[i-1][4]+DP[i-1][5]+DP[i-1][6]+DP[i-1][7];
		DP[i][6] =            DP[i-1][2]+DP[i-1][3]+DP[i-1][4]+DP[i-1][5]+DP[i-1][6]+DP[i-1][7];
		DP[i][7] = DP[i-1][1]+DP[i-1][2]+DP[i-1][3]+DP[i-1][4]+DP[i-1][5]+DP[i-1][6]+DP[i-1][7];

		if(S[i-1]=='J'){
			DP[i][0] = DP[i][1] = DP[i][2] = DP[i][3] = 0;
		}
		else if(S[i-1]=='O'){
			DP[i][0] = DP[i][1] = DP[i][4] = DP[i][5] = 0;
		}
		else if(S[i-1]=='I'){
			DP[i][0] = DP[i][2] = DP[i][4] = DP[i][6] = 0;
		}

		for(int j=0; j<8; j++){
			DP[i][j] %= 10007;
		}
	}

	int sum = 0;

	for(int j=0; j<8; j++){
		sum += DP[N][j];
	}

	cout << sum%10007 << endl;

	return 0;
}

Measured memory_bytes: 1232
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;
typedef long long ll;

int main() {
    int D;
    cin >> D;
    vector<int> c(26);
    for (int i = 0; i < 26; i++) {
        cin >> c.at(i);
    }
    vector<vector<int>> s(D, vector<int>(26));
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < 26; j++) {
            cin >> s.at(i).at(j);
        }
    }
    vector<int> t(D);
    for (int i = 0; i < D; i++) {
        cin >> t.at(i);
    }
    int ans = 0;
    vector<int> last(26, 0);
    for (int i = 0; i < D; i++) {
        last.at(t.at(i) - 1) = i + 1;
        for (int j = 0; j < 26; j++) {
            if (t.at(i) == j + 1) {
                ans += s.at(i).at(t.at(i) - 1);
            }
            else {
                ans -= (i + 1 - last.at(j)) * c.at(j);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 

using namespace std;

int findSumOfDigits(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

int main() {
    int N;

    cin >> N;

    int sum = findSumOfDigits(N);

    if (N % sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=1e5+3;
string s,p,x;
//map<string,int>mp;
//vector<int>v;

int main()
{
    ft
    ll t,i,j,n,m,l,r,c;
    cin>>n;
    c=(n/500)*1000;
    n%=500;
    c+=(n/5)*5;
    cout<<c<<"\n";
    return 0;
}



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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    vector<int> pack;
    pack.push_back(a);
    pack.push_back(b);
    pack.push_back(c);
    sort(pack.begin(),pack.end());
    if (pack[0]+pack[1] == pack[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }

fun main(args: Array<String>) {
    val (N, M, C) = readInts()
    val B = readInts()

    println(
        Array(N) { readInts() }
            .map { it.foldIndexed(C) { index, sum, value -> sum + (value * B[index]) } }
            .filter { it > 0 }
            .count()
    )
}

Measured memory_bytes: 37924
"use strict"
 
const arg_str = require('fs').readFileSync('/dev/stdin', 'UTF-8')
const args= arg_str.split('\n')
const N = parseInt(args[0])
const a_array = args[1].split(' ').map(x=>parseInt(x))

for(let i=N;i>=1;i--){
  for(let j=2;i*j<=N;j++){
    a_array[i-1] ^= a_array[i*j-1]
  }
}

const result = []
a_array.forEach((item, index)=>{
  if(item==1){
    result.push(index+1)
  }
})
 
console.log(result.length)
if(result.length > 0){
  console.log(result.join(' '))
}

Measured memory_bytes: 23420
m=[0]*50
f=[0]*50
r=[0]*50
result=[""]*50

num=0
while True:
  a,b,c=map(int,input().split())
  if a == b == c ==-1:
    break
  else:
    m[num],f[num],r[num]=a,b,c
  num+=1

for i in range(num):
  if m[i] == -1 or f[i]==-1:
    result[i]="F"
  elif m[i]+f[i]>=80:
    result[i]="A"
  elif m[i]+f[i]>=65:
    result[i]="B"
  elif m[i]+f[i]>=50:
    result[i]="C"
  elif m[i]+f[i]>=30:
    if r[i] >=50:
      result[i]="C"
    else:
      result[i]="D"
  else:
    result[i]="F"

for i in range(num):
  print(result[i])


Measured memory_bytes: 5608
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
const int INF = 1000000000;

int main() {
  IN(N);

  vvi edge(N, vi(N, INF));
  REP(i, N) {
    IN(u);
    IN(k);
    REP(j, k) {
      IN(v); IN(c);
      edge[u][v] = c;
    }
  }

  int cost[N];
  priority_queue<pii, vector<pii>, greater<pii> > q;
  fill(cost, cost + N, INF);
  cost[0] = 0;
  q.push(make_pair(0, 0));

  while (!q.empty()) {
    pii p = q.top(); q.pop();
    int u = p.second;
    int cur_cost = p.first;

    if (cost[u] < cur_cost)
      continue;
    for (int v = 0; v < N; ++v) {
      if (edge[u][v] == INF)
        continue;
      if (cost[v] > cost[u] + edge[u][v]) {
        cost[v] = cost[u] + edge[u][v];
        q.push(make_pair(cost[v], v));
      }
    }
  }

  REP(i, N) {
    OUT(i << " " << cost[i]);
  }

  return 0;
}



Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;

int main(){
    int N;
    cin >> N;
    vector<LL>  a(N);
    LL L = 0;
    for(int i = 0;i < N;i++)    {
        cin >> a[i];
        L += a[i];
    }
    LL ans = 1e18;
    LL len = 0;
    for(int i = 0;i < N;i++){
        len += a[i];
        ans = min(ans, max(len, L-len)-min(len, L-len));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

char s[27];
int main(){
  int flag = 0;
  cin >> s;
  for (int i =0;i<strlen(s);i++){
    for(int j = i+1; j<strlen(s);j++){
      if (s[i] == s[j]) flag = 1;
    }
  }
  
  (flag==1)?(cout << "no" << endl):(cout <<"yes" << endl);
  
  return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int, int> ii;

const ll mod = 1e9 + 7;
const ll INF = (1LL<<50);
const double EPSILON = 0.001;
const int N = 2005;
int main(){
	fastio;
	int n;
	cin >> n;
	vector<ii>v(n);
	for(int i = 0; i < n; i++)
		cin >> v[i].fst >> v[i].snd;
	int ans = 0;
	for(int i = 0; i < n-2; i++){
		if(v[i].fst == v[i].snd and v[i+1].fst == v[i+1].snd and v[i+2].fst==v[i+2].snd)
			ans = 1;
	}
	cout << (ans?"Yes":"No") << '\n';
	return 0;
}


Measured memory_bytes: 3648
def calc(p):
    n = len(p) - 1
    m = [[None for i in range(n + 1)] for j in range(n + 1)]
    for x in range(n):
        m[x][x] = 0
    for l in range(2, n + 1):
        for i in range(0, n - l + 1):
            j = i + l - 1
            m[i][j] = float("inf")
            for k in range(i, j):
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j])
    return m

n = int(input())
p = []
for i in range(n):
    inp = list(map(int, input().split()))
    if i == 0:
        p.append(inp[0])
        p.append(inp[1])
    elif 0 < i < n - 1:
        p.append(inp[1])
    elif i == (n - 1):
        p.append(inp[1])

m = calc(p)
print(m[0][n - 1])

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int K;
  cin >> K;
  int cur = 0;
  for (int i = 0; i < K; i++) {
    cur = cur * 10 + 7;
    cur %= K;
    if (cur == 0) {
      cout << i + 1 << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}


Measured memory_bytes: 3660
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    vector<int> solve(vector<int>& A, vector<int>& B, vector<int>& L, vector<int>& R) {
        int n = A.size();
        int m = L.size();

        vector<int> X(A);
        sort(X.begin(), X.end());
        auto index = [&](int x) {
            return lower_bound(X.begin(), X.end(), x) - X.begin();
        };
        for (int i = 0; i < n; ++i) {
            A[i] = index(A[i]);
        }
        {
            auto T = B;
            for (int i = 0; i < n; ++i) {
                B[A[i]] = T[i];
            }
        }
        vector<int> D(n + 1, 0);
        D[0] = B[0];
        D[n] = B[n - 1];
        for (int i = 1; i < n; ++i) {
            D[i] = B[i] ^ B[i - 1];
        }

        vector<vector<pair<int,int>>> graph(n + 1);

        for (int i = 0; i < m; ++i) {
            int l = index(L[i]);
            int r = index(R[i]);
            if (r < n && X[r] == R[i]) {
                ++r;
            }
            graph[l].emplace_back(r, i);
            graph[r].emplace_back(l, i);
        }

        vector<int> res;
        vector<bool> visited(n + 1, false);
        function<void(int)> dfs = [&](int u) {
            visited[u] = true;
            for (auto& e : graph[u]) {
                int v = e.first;
                int idx = e.second;
                if (!visited[v]) {
                    dfs(v);
                    if (D[v]) {
                        D[u] ^= 1;
                        res.push_back(idx);
                    }
                }
            }
        };

        for (int i = 0; i <= n; ++i) {
            if (!visited[i]) {
                dfs(i);
                if (D[i]) {
                    return {};
                }
            }
        }

        sort(res.begin(), res.end());
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    int m;
    cin >> n >> m;
    vector<int> A(n);
    vector<int> B(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i] >> B[i];
    }
    vector<int> L(m);
    vector<int> R(m);
    for (int i = 0; i < m; ++i) {
        cin >> L[i] >> R[i];
    }
    Solution sol;
    auto res = sol.solve(A, B, L, R);
    if (res.empty()) {
        if (count(B.begin(), B.end(), 1) == 0) {
            cout << 0 << "\n";
        } else {
            cout << -1 << "\n";
        }
    } else {
        cout << res.size() << "\n";
        for (int i = 0; i < res.size(); ++i) {
            cout << res[i] + 1 << (i + 1 < res.size() ? ' ' : '\n');
        }
    }
    return 0;
}

Measured memory_bytes: 20216
bingo = [[0]*3]*3

for i in range(3):
  bingo[i] = list(map(int, input().split()))

N = int(input())

for i in range(N):
  a = int(input())
  for j in range(3):
    for k in range(3):
      if bingo[j][k] == a:
        bingo[j][k] = 200

if bingo[0][0] == bingo[1][0] == bingo[2][0] or bingo[0][1] == bingo[1][1] == bingo[2][1] or bingo[0][2] == bingo[1][2] == bingo[2][2] or bingo[0][0] == bingo[1][1] == bingo[2][2] or bingo[0][2] == bingo[1][1] == bingo[2][0] or bingo[0][0] == bingo[0][1] == bingo[0][2] or bingo[1][0] == bingo[1][1] == bingo[1][2] or bingo[2][0] == bingo[2][1] == bingo[2][2]:
  print("Yes")
else:
  print("No")

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

int main(int argc, char const *argv[]) {
  int a,b;
  cin>>a>>b;
  int ans=0;
  for(int i=0;i<2;i++){
    if(a>b){
      ans+=a;
      a--;
    }else{
      ans+=b;
      b--;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 100005;
int n, l[MX], r[MX];
long long ans, t;
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d%d", l+i, r+i);
		l[i] = -l[i];
	}
	sort(l,l+n); sort(r,r+n);
	rep(i,n){
		ans = min(ans, t + min({r[i] + l[i], r[i], l[i]}));
		t += r[i] + l[i];
	}
	printf("%lld\n", -ans*2);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a)  (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

const ll INF = 1LL << 60;

int main(){
  int n,m; cin >> n >> m;
  vector<pii> x;
  rep(i, n){
    int a; cin >> a;
    x.push_back(make_pair(a,1));
  }
  rep(i, m){
    int b,c; cin >> b >> c;
    x.push_back(make_pair(c,b));
  }

  sort(all(x),greater<pii>());

  vi a;
  int i = 0;
  while(a.size() < n){
    int b = x[i].second;
    rep(j, b){
      if(a.size() < n) a.push_back(x[i].first);
    }
    i++;
  }

  ll sum = 0;
  rep(j, n) sum += a[j];

  std::cout << sum << '\n';
}


Measured memory_bytes: 2672
// ※※※ 解答不能 ※※※
// square1001氏.
// https://atcoder.jp/contests/code-festival-2016-qualc/submissions/1992158
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int n, c, p[500009], ip[500009], v[500009], bit[500009], inv[500009], mod = 1000000007;
void add(int pos, int val){
    for(int i = pos + 1; i <= n; i += i & (-i)) bit[i] += val;
}
int sum(int pos){
    int ret = 0;
    for(int i = pos; i >= 1; i -= i & (-i)) ret += bit[i];
    return ret;
}
int main(){
    scanf("%d", &n);
    inv[1] = 1;
    repx(i, 2, n + 1) inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
    rep(i, n) ip[i] = -1;
    repr(i, n - 1, 0){
        scanf("%d", &p[i]), p[i]--;
        if(p[i] != -1) ip[p[i]] = i;
    }
    int f1 = 1;
    rep(i, n){
        if(ip[i] == -1){
            v[c++] = i;
            f1 = 1LL * f1 * c % mod;
        }
    }
    int ret = 0, fact = 1, cur = 0, cs = 0;
    rep(i, n){
        if(p[i] != -1){
            ret = (ret + 1LL * fact * sum(p[i]) % mod * f1) % mod;
            ret = (ret + 1LL * fact * (lower_bound(v, v + c, p[i]) - v) % mod * f1 % mod * inv[c] % mod * cur) % mod;
            cs += c - (lower_bound(v, v + c, p[i]) - v);
            if(cs >= mod) cs -= mod;
            add(p[i], 1);
        }else{
            ret = (ret + 1LL * fact * cs % mod * f1 % mod * inv[c]) % mod;
            ret = (ret + 1LL * fact * cur % mod * f1 % mod * inv[2]) % mod;
            cur++;
        }
        fact = 1LL * fact * (i + 1) % mod;
    }
    printf("%d\n", (ret + f1) % mod);
    return 0;
}

Measured memory_bytes: 9984