akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
using namespace std;

char imap[101][101];
int H, W;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};

void dfs(int x, int y, char c){
    imap[x][y] = '.';
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i], ny = y+dy[i];
        if (nx >= 0 && nx < H && ny >= 0 && ny < W && imap[nx][ny] == c) dfs(nx, ny, c);
    }
}

int main() {

    char a[101];
    int sum;
    for (; ;) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0) break;
        sum = 0;
        for (int i = 0; i < H; i++) {
            scanf("%s", a);
            for (int j = 0; j < W; j++) {
                imap[i][j] = a[j];
            }
        }

        for (int i = 0; i < H; i++) {
            for (int j= 0; j < W; j++) {
                if (imap[i][j] != '.') {
                    dfs(i, j, imap[i][j]);
                    sum++;
                }
            }
        }
        printf("%d\n", sum);
    }
    return 0;
}



Measured memory_bytes: 3068
import java.util.Scanner;

public class Main {
  public static int gcd(int x, int y) {
  	if (x % y == 0) {
      return y;
    }
    return gcd(y, x % y);
  }
  
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int num = Integer.parseInt(input.nextLine());
    long sum = 0;
    
    // System.out.println(gcd(390, 273));
    
    for (int i = 1; i <= num; i++) {
      for (int j = 1; j <= num; j++) {
        for (int k = 1; k <= num; k++) {
          sum += gcd(gcd(i,j),k);
        }
      }
    }
    
    System.out.print(sum);
  }
}

Measured memory_bytes: 35744
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,  int>;

const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

ll dp[110][101010];
ll sum[101010];
int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){cin >> a[i];} 
	
	dp[0][0]=1;
	for(int i = 1; i <= n; ++i){
		sum[0]=0;
		for(int j = 0; j<= k; ++j){
			sum[j+1] = (sum[j]+dp[i-1][j]) % MOD;
        }
		for(int j =0; j <= k; ++j){
	        dp[i][j] += (sum[j+1] - sum[max(0, j-a[i-1])] + MOD)% MOD;
       }
    }
    
    cout << dp[n][k] << endl;
}

Measured memory_bytes: 81408
using System;
using System.Collections.Generic;
using System.IO;

class Program
{
    static int[] dx = new int[] { 0, 0, 1, -1 };
    static int[] dy = new int[] { -1, 1, 0, 0 };
    static void Solve()
    {
        var h = sc.Int();
        var w = sc.Int();

        var s = new string[h];
        var dist = new int[h][];

        for (int i = 0; i < h; i++)
        {
            s[i] = sc.Str();
            dist[i] = new int[w];

            for (int j = 0; j < w; j++)
                dist[i][j] = -1;
        }

        var cnt = 0;

        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                if (s[i][j] == '#')
                    cnt++;

        dist[0][0] = 0;

        var q = new Queue<Coord>();
        q.Enqueue(new Coord { x = 0, y = 0 });

        while (q.Count > 0)
        {
            var now = q.Dequeue();
            var x = now.x;
            var y = now.y;

            for (int i = 0; i < 4; i++)
            {
                var nx = x + dx[i];
                var ny = y + dy[i];

                if (nx < 0 || w <= nx || ny < 0 || h <= ny || s[ny][nx] == '#' || dist[ny][nx] != -1)
                    continue;

                dist[ny][nx] = dist[y][x] + 1;

                q.Enqueue(new Coord { x = nx, y = ny });
            }
        }

        if (dist[h - 1][w - 1] == -1)
            Console.WriteLine(-1);
        else
            Console.WriteLine(w * h - cnt - dist[h - 1][w - 1] - 1);
    }

    class Coord
    {
        public int x;
        public int y;
    }
    static void Main(string[] args)
    {
        // pr.AutoFlush = true;
        Solve();
        pr.Flush();
    }

    static Scanner sc = new Scanner();
    static Printer pr = new Printer();
}

#region IO
class Scanner
{
    private int _i = 0;
    private string[] line = new string[0];

    private T[] Enumerate<T>(int n, Func<T> f)
    {
        T[] ret = new T[n];
        for (int i = 0; i < n; i++)
            ret[i] = f();
        return ret;
    }

    public string Str()
    {
        if (line.Length <= _i)
        {
            line = Console.ReadLine().Split(' ');
            _i = 0;
        }

        return line[_i++];
    }

    public int Int() => int.Parse(Str());
    public long Long() => long.Parse(Str());
    public double Double() => double.Parse(Str());
    public int[] Int(int n) => Enumerate(n, Int);
    public long[] Long(int n) => Enumerate(n, Long);
    public double[] Double(int n) => Enumerate(n, Double);
    public string[] Str(int n) => Enumerate(n, Str);
}

class Printer : StreamWriter
{
    public Printer() : base(Console.OpenStandardOutput())
    {
        AutoFlush = false;
    }
}
#endregion

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

int main(){
    int N; cin >> N; ll C; cin >> C;
    ll x[100100], v[100100];
    x[0]=0; v[0]=0;
    for(int i=0; i<N; i++){
        cin >> x[i+1] >> v[i+1];
    }
    x[N+1]=C; v[N+1]=0;
    N+=2;
    ll sum[100100];
    sum[0]=0;
    for(int i=0; i<N; i++){
        sum[i+1] = sum[i]+v[i];
    }
    vector<int> r_toku(0), l_toku(0);
    ll rmax=0, lmax=0;
    for(int i=0; i<N; i++){
        if( rmax <= sum[i+1]-x[i]) r_toku.push_back(i);
        if( lmax <= sum[N]-sum[N-1-i] - (C- x[N-1-i]) ) l_toku.push_back(N-1-i); 
        rmax = max(rmax, sum[i+1]-x[i]);
        lmax = max(lmax, sum[N]-sum[N-1-i] - (C- x[N-1-i]) );
    }
    sort(r_toku.begin(),r_toku.end());
    sort(l_toku.begin(),l_toku.end());
    ll ans =0;
    for(int i=0; i<N-1; i++){
        int j = *lower_bound(l_toku.begin(), l_toku.end(),i+1 );
        ll val=sum[N]-sum[j]+sum[i+1]-2*x[i]-(C-x[j]);
        ans = max(ans, val);
    }
    for(int i=1; i<N; i++){
        int j = *( lower_bound(r_toku.begin(), r_toku.end(), i)-1 );
        ll val = sum[N]-sum[i]+sum[j+1]-2*(C-x[i])-x[j];
        ans =max(ans, val);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
class DoublyLinkedList {
  constructor() {
    this.list = {
      next: null,
    };
    this.first = null;
    this.last = null;
  }

  insert(value) {
    if (this.first === null) {
      this.list = {
        next: {
          prev: null,
          value: value,
          next: null,
        },
      };
      this.first = this.list.next;
      this.last = this.list.next;
    } else {
      const secondNode = this.list.next;
      this.list = {
        next: {
          prev: null,
          value: value,
          next: secondNode,
        },
      };
      secondNode.prev = this.list.next;
      this.first = this.list.next;
    }
  }

  remove(value) {
    let node = this.list.next;
    while (true) {
      if (node === null || node.value === value) {
        break;
      }
      node = node.next;
    }
    this.removeNode(node);
  }

  removeNode(node) {
    if (!node) return;

    if (node.prev) {
      node.prev.next = node.next;
    } else {
      // node is first
      this.first = node.next;
      this.list.next = this.first;
    }

    if (node.next) {
      node.next.prev = node.prev;
    } else {
      // node is last;
      this.last = node.prev;
    }
    
    node = null;
  }

  deleteFirst() {
    this.removeNode(this.first);
  }

  deleteLast() {
    this.removeNode(this.last);
  }

  print() {
    const str = [];
    let node = this.first;
    while (!!node) {
      str.push(node.value);
      node = node.next;
    }
    console.log(str.join(' '));
  }
}

const proc = (arr) => {
  const list = new DoublyLinkedList();

  arr.shift(); // for N
  arr.forEach((element) => {
    const [cmd, v] = element.split(' ');

    if (cmd === 'insert') {
      list.insert(v);
      return;
    }

    if (cmd === 'delete') {
      list.remove(v);
      return;
    }

    if (cmd === 'deleteFirst') {
      list.deleteFirst();
      return;
    }

    if (cmd === 'deleteLast') {
      list.deleteLast();
      return;
    }
  });

  list.print();
};

let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
process.stdin.on('end', function() {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    proc(inputString);
});









Measured memory_bytes: 359500
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,n,m,k,q; 
    t = 1;
    a = b = c = n = 0;
    cin>>t;
    while(t--)
    {
    	string s;
    	cin>>s;
    	if(s=="AC")
    		a++;
    	else if(s=="TLE")
    		b++;
    	else if(s=="WA")
    		c++;
    	else
    		n++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<c<<endl;
    cout<<"TLE x "<<b<<endl;
    cout<<"RE x "<<n<<endl;
    return 0;
}

Measured memory_bytes: 3652
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
ll fun(ll n)
{
	if(n<0)
		return 0;
	return (n*(n-1))/2;	
}
int main()
{
	fast();
	ll n,i;
	cin>>n;
	ll a[n],ans=0;
	umap<ll,ll> m;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		m[a[i]]++;	
	}
	for(auto it : m)
	{
		ll temp=it.ss;
		ans+=fun(temp);
	}
	for(i=0;i<n;i++)
	{
		ll temp=m[a[i]];
		ll z=ans-fun(temp);
		z=z+fun(temp-1);
		cout<<z<<endl;
	}
	
}

Measured memory_bytes: 10312
import java.util.*;

public class Main{

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args){
        new Main().run();
    }

    void run() {

        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();

        for (int i=0; i<s.length; i++) {
            if (s[i] != t[i]) {
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");

    }
}


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
  int h, w, k;
  cin >> h >> w >> k;
  vs c(h);
  rep(i,h) cin >> c[i];
  int ans = 0;
  rep(ci,(1<<h)) {
    rep(cj,(1<<w)) {
      int tmp = 0;
      vs s = c;
      rep(i,h)rep(j,w) {
        if((ci&(1<<i)) || (cj&(1<<j))) s[i][j] = ':';
      }
      rep(i,h)rep(j,w) {
        if(s[i][j] == '#') tmp++;
      }
      if(tmp == k) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+7;
const int sz = 31;

int n,m,ar[maxn];
multiset<int> s;
multiset<int>::iterator it;
int main()
{ 
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d", ar+i);
        s.insert(ar[i]);
    }
    for(int i=1;i<=n;i++){
        s.erase(s.find(ar[i]));
        it = s.end();
        it--;
        printf("%d\n", *it);
        s.insert(ar[i]);
    }

    return 0;
}


Measured memory_bytes: 11776
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 

vll dp(100100);

ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  vll A(n);
  FOR(i,0,n){
    ci(A[i])
  }
  ll ans=0;
  FOR(i,0,n){
    FOR(j,0,n){
      if(i!=j){
        ans+=A[i]*A[j];
      }
    }
  }
  co(ans/2)
}

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



int main() {
	long long int n, h;
	cin >> h;
	cin >> n;

	vector<pair<long long int, long long int> > v;
	vector<long long int> dp(h+1, 1e17);
	dp[0] = 0;
	for (long long int i=0; i<n; i++) {
		long long int a, b;
		cin >> a;
		cin >> b;
		v.push_back(make_pair(a, b));
	}
	
	long long int zero = (long long int) 0;	
	for (int i=0; i<h+1; i++) {
		for (int j=0; j<n; j++) {

			dp[i] = min(dp[i], dp[max(zero, i-v[j].first)] + v[j].second);
		}
	}


	cout << dp[h] << "\n";
	
	return 0;
			
}	


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e10;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool ok = 1;
    int c = 0;
    if (s[0] != 'A') ok = 0;
    rep(i,2,s.length()-1){
        if (s[i] == 'C') c++;
    }
    if (c != 1 || s[1] == 'C' || s[s.length()-1] == 'C') ok = 0;
    rep(i,1,s.length()){
        if (s[i] == 'A') ok = 0;
        if (s[i] == 'C') continue;
        if (isupper(s[i])) ok = 0;
    }
    if (ok) PRINT("AC");
    else PRINT("WA");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const lli mod = 1e9+7;

int main(){
	string s;
	cin >> s;
	vector<vector<lli>> dp(4, vector<lli>(s.length()+1, 0));
	dp[0][0] = 1;
	for(int i=0; i<(int)s.length(); i++){
		for(int d=0; d<3; d++){
			dp[d][i] %= mod;
			if(s[i] == ('A'+d)){
				dp[d+1][i+1] += dp[d][i];
				dp[d][i+1] += dp[d][i];
			}else if(s[i] == '?'){
				dp[d+1][i+1] += dp[d][i];
				dp[d][i+1] += dp[d][i] *3;
			}else{
				dp[d][i+1] += dp[d][i];
			}
		}
		dp[3][i] %= mod;
		if(s[i] == '?'){
			dp[3][i+1] += dp[3][i] *3;
		}else{
			dp[3][i+1] += dp[3][i];
		}
	}
	cout << dp[3][s.length()] %mod << endl;
	return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
  long A,B; cin>>A>>B;
  int i=1;
  long ans;
  bool jud = false;
  if (A>B) swap(A,B);
  while(jud == false){
    if ((B*i)%A == 0){
      jud = true;
      ans = B*i;
    }
    i++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define el "\n"
#define sp " "
typedef long long ll;
string s;
main()
{
	ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
vector<ll> a(n+1);
map<ll,ll> m;
for(ll i=1;i<=n;i++)
cin>>a[i],m[i-a[i]]++;
ll ans=0;
for(ll i=1;i<=n;i++)
ans+=m[i+a[i]];
cout<<ans;

}

Measured memory_bytes: 27396
#include <iostream>
#include <string.h>
#include <cstdint>
using namespace std;

int digitSum(int n)
{
	int sum = 0;
	while(n) {
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

int main() {
	int n;
	int a, b;
	int min = INT32_MAX;

	cin >> n;

	for( a = 1; a < n; a++ ) {
		b = n - a;
		int sum = 0;
		sum += digitSum(a);
		sum += digitSum(b);
		if( sum < min ) {
			min = sum;
		}
	}

	cout << min << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int MOD = 1000000007;

template <int MOD> struct modint
{
	long long val;
	modint(long long a=0) : val(a % MOD) {
		if (val < 0) val += MOD;
	}
	modint operator -() const {return modint(MOD - val);}
	modint &operator +=(const modint &r) {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	modint &operator -=(const modint &r) {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	modint &operator *=(const modint &r) {
		val *= r.val;
		val %= MOD;
		return *this;
	}
	modint operator +(const modint &r) const {return modint(*this) += r;}
	modint operator -(const modint &r) const {return modint(*this) -= r;}
	modint operator *(const modint &r) const {return modint(*this) *= r;}
	bool operator ==(const modint &r) const {return val == r.val;}
	bool operator !=(const modint &r) const {return val != r.val;}
	operator long long() const {return val;}
};
using mint = modint<MOD>;

long long pow_mod(long long a, long long n) {
	long long ret = 1;
	while (n != 0) {
		if (n & 1) ret = (ret * a) % MOD;
		n >>= 1;
		a = (a * a) % MOD;
	}
	return ret;
}

int main() {
	int n, k;
	cin >> n >> k;
	mint d[100001];
	for (int i = 1; i <= k; i++) {
		d[i] = pow_mod(k/i, n);
	}
	for (int i = k; i >= 1; i--) {
		for (int j = 2*i; j <= k; j += i) {
			d[i] -= d[j];
		}
	}
	mint ans = 0;
	for (int i = 1; i <= k; i++) {
		ans += d[i] * mint(i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4420
// 2009ツアツジツアツ地ツ凝ヲツ予ツ選 B : Repeated Substitution with Sed
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <queue>

using namespace std;

string replaceAll(string s, string a, string b){
	for(int p=s.find(a);p!=-1;p=s.find(a,p+b.size()))
		s.replace(p, a.size(), b);
	return s;
}

int search(vector<string> a, vector<string> b, string c, string d){
	queue< pair<string, int> > qu; qu.push(make_pair(c,0));
	set<string> S; S.insert(c);
	while(!qu.empty()){
		pair<string, int> p = qu.front(); qu.pop();
		for(int i=0;i<a.size();i++){
			string t = replaceAll(p.first, a[i], b[i]);
			if(t == d) return p.second + 1;
			if(t.size()<d.size()&&S.find(t)==S.end()){
				S.insert(t);
				qu.push(make_pair(t,p.second+1));
			}
		}
	}
	return -1;
}

int main(){
	int n;
	while(cin >> n, n){
		vector<string> a(n), b(n);
		for(int i=0;i<n;i++) cin >> a[i] >> b[i];
		string c, d;
		cin >> c >> d;
		cout << search(a, b, c, d) << endl;
	}
}

Measured memory_bytes: 0
S = input()

mod = 10 ** 9 + 7

# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i + 1)]  # 後ろから一桁ずつみていく
    if x == "?":
        for k in range(10): # ?が0~9であった時、それぞれのケースについて調べる
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= mod
    else:
        k = int(x)
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= mod
    mul = mul * 10 % 13  # 計算量削減のためここで13で割っている

print(dp[len(S)][5])

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

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 998244353
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 8;

int N, A, B, C;
int L[MAX_N];

int AA, BB, CC;
int ans = INF_LL;

void dfs(int pos, int cnt, int AA, int BB, int CC)
{
  if(pos == N) {
    if(AA == 0 || BB == 0 || CC == 0) {
      return;
    }
    ans = min(ans, abs(A - AA) + abs(B - BB) + abs(C - CC) + 10*(cnt-3));
  } else {
    dfs(pos+1, cnt+1, AA+L[pos], BB, CC);
    dfs(pos+1, cnt+1, AA, BB+L[pos], CC);
    dfs(pos+1, cnt+1, AA, BB, CC+L[pos]);
    dfs(pos+1, cnt, AA, BB, CC);
  }
}

signed main()
{
  cin >> N >> A >> B >> C;
  REP(n,N) {
    cin >> L[n];
  }

  dfs(0,0,0,0,0);

  cout << ans << endl;

  return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int uf[40001];

int find(int n){
  if(uf[n]==n) return n;
  else return uf[n]=find(uf[n]);
}

void uni(int m,int n){
  uf[find(m)]=find(n);
  return;
}

int main(){
  int n,w,h;
  cin >> n >> w >> h;
  map<int,int> xset,yset;
  bool kabeflag=false;
  for(int i=0;i<=n;i++){
    uf[i]=i;
  }
  int x,y;
  for(int i=1;i<=n;i++){
    cin >> x >> y;
    if(x==1||x==w||y==1||y==h){
      kabeflag=true;
    }
    if(xset[x]){
      uni(i,xset[x]);
    }else{
      xset[x]=i;
    }
    if(yset[y]){
      uni(i,yset[y]);
    }else{
      yset[y]=i;
    }
  }
  vector<int> isroot(n+1,0);
  for(int i=1;i<=n;i++){
    isroot[find(i)]=1;
  }
  int count=0;
  vector<int> hasi(4,0);
  for(int i=1;i<=n;i++){
    count+=isroot[i];
  }
  if(count==1){
    cout << n-1 << endl;
  }else{
    if(kabeflag){
      cout << n-1+count-1 << endl;
    }else{
      cout << n-1+count << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 6260
import java.util.Scanner;

class Main{

	public static void insertionSort(int A[],int N){
		for(int k=0;k<N-1;k++){
			System.out.print(A[k]+" ");
		}
		System.out.println(A[N-1]);
		for(int i=1;i<N;i++){
			int v=A[i];
			int j=i-1;
			while(j>=0 && A[j]>v){
				A[j+1]=A[j];
				j--;
			}
			A[j+1]=v;
			for(int k=0;k<N-1;k++){
				System.out.print(A[k]+" ");
			}
			System.out.println(A[N-1]);
		}
		
	}

	public static void  main(String[] args){
		Scanner scan =new Scanner(System.in);
		int n = scan.nextInt();
		int array[]=new int[n];

		for(int i=0;i<n;i++)
			array[i]=scan.nextInt();

		insertionSort(array,n);
		
		
			
		scan.close();
	}

}

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

using namespace std;

const int BaseMoney = 600;

int judge(const int sumLength, int w) {
	int index;

	if (w <= 2 && sumLength <= 60) {
		index = 0;
	}
	else if (w <= 5 && sumLength <= 80) {
		index = 1;
	}
	else if (w <= 10 && sumLength <= 100) {
		index = 2;
	}
	else if (w <= 15 && sumLength <= 120) {
		index = 3;
	}
	else if (w <= 20 && sumLength <= 140) {
		index = 4;
	}
	else if (w <= 25 && sumLength <= 160) {
		index = 5;
	}
	else {
		return 0;
	}

	return BaseMoney + 200 * index;
}

int main(void) {
	int n, x, y, h, w, sumLength, sum;

	while (cin >> n, n) {
		sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> x >> y >> h >> w;

			sumLength = x + y + h;
			sum += judge(sumLength, w);
		}
		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 3072
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();
        int ans = -1;
        int num = 0;
        for (int i = 1; i <= n; i++) {
            num = (num * 10 + 7) % n;
            if (num == 0) {
                ans = i;
                break;
            }
        }
        System.out.println(ans);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 32564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
 
bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
string s;
bool f = false,f2 = false;
string ans = "keyence";
int pos;
string kou;
int mem,po;
bool ok = true;
int main(){
    cin >> s;
    
    pos = 0;
    if(s[0] == 'k'){
        for(int i = 0; i < s.length(); i++){
            if(ans[pos] == s[i])    ++pos;
            else{
                po = pos;
                for(int j = i; j < s.length(); j++){
                    if(s[j] == ans[pos]){
                        ++pos;
                    }
                    else{
                        pos = po;
                        if(s[j] == ans[pos])    ++pos;
                    }
                    if(pos == ans.length()){
                        if(j == s.length()-1){
                            cout << "YES\n";
                            return 0;
                        }
                        pos = po;
                    }
                }
                break;
            }
            if(pos == ans.length()){
                cout << "YES\n";
                return 0;
            }
        }
    }

    pos = ans.length()-1;
    for(int i = s.length()-1; i >= 0; i--){
        if(s[i] == ans[pos]){
            --pos;
        }
        else{
            break;
        }
        if(pos == -1){
            cout << "YES\n";
            return 0;
        }
    }

    cout << "NO\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;

char map[55][55];
bool vis[55][55];
int H, W;
struct node
{
	int x, y;
	int step;
	node(int _x, int _y, int _s) :x(_x), y(_y), step(_s) {}
	node() {}
};
int dir[4][2] = { -1,0,1,0,0,-1,0,1 };
int bfs()
{
	if (map[1][1] == '#' || map[H][W] == '#')return -1;
	queue<node>Q;
	Q.push(node(1, 1, 0));
	while (!Q.empty())
	{
		node u = Q.front();Q.pop();
		int x = u.x, y = u.y, step = u.step;
		if (vis[x][y])continue;
		vis[x][y] = 1;
		if (x == H&&y == W)return step;
		int tmpx, tmpy;
		for (int i = 0;i < 4;i++)
		{
			tmpx = x + dir[i][0];
			tmpy = y + dir[i][1];
			if (tmpx <= 0 || tmpx > H || tmpy <= 0 || tmpy > W)continue;
			if (vis[tmpx][tmpy])continue;
			if (map[tmpx][tmpy] == '#')continue;
			Q.push(node(tmpx, tmpy, step + 1));
		}
	}
	return -1;
}

int main()
{

	scanf("%d %d", &H, &W);
	int all = H*W;
	int black = 0;
	for (int i = 1;i <= H;i++)
	{
		scanf("%s", map[i] + 1);
	}
	for (int i = 1;i <= H;i++)
		for (int j = 1;j <= W;j++)
			if (map[i][j] == '#')
				black++;
	int dis = bfs();
	if (dis == -1)
		puts("-1");
	else
	{
		printf("%d\n", all - black - dis - 1);
	}
}

Measured memory_bytes: 256
n, m = map(int, input().strip().split())
h = list(map(int, input().strip().split()))
to=[[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().strip().split())
    to[a-1].append(b-1)
    to[b-1].append(a-1)
ans=0
for i in range(n):
    good=True
    for j in to[i]:
        if h[i]<=h[j]:
            good=False
            break
    if good:
        ans+=1
print(ans)

Measured memory_bytes: 29452
import math
cnt = 0

def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
    return A

def shellSort(A, n):
    i = len(A)
    G = [(3**j-1)//2 for j in range(int(math.log(2*i+1, 3)),0,-1)]
    m = len(G)
    for g in G:
        insertionSort(A, n, g)
    return m, G, A


n = int(input())
a = [int(input()) for _ in range(n)]
m, g, sa = shellSort(a[:], n)
print(m)
print(' '.join(map(str,g)))
print(cnt)
print('\n'.join(map(str,sa)))


Measured memory_bytes: 133856
h, w, k = map(int, input().split())
C = []
for _ in range(h): C.append(input())
import itertools
ans = 0
for bit in range(1<<(h+w)):
    c = 0
    for i in range(w, h+w):
        for j in range(w):
            if bit>>i & 1 and bit>>j & 1: c += C[i-w][j] == '#'
    if c == k: ans += 1
print(ans)


Measured memory_bytes: 9156
#include<iostream>
using namespace std;
int main(){
	int n[28],a[30],x,d,e;
	for(int i=0;i<30;i++){
		a[i]=i+1;
	}
	for(int i=0;i<28;i++){
		cin >> n[i];
		x=n[i];
		for(int i=0;i<30;i++){
			if(x==a[i])a[i]=0;
		}
	}
	for(int i=0;i<30;i++){
		if(a[i]!=0){
			d=a[i];
			a[i]=0;
			for(int i=0;i<30;i++){
				if(a[i]!=0){
					e=a[i];
					if(d<e){
						cout << d <<endl;
						cout << e <<endl;
						return 0;
					}else if(d<e){
						cout << e <<endl;
						cout << d <<endl;
						return 0;
					}

				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1164
#https://atcoder.jp/contests/abc161/tasks/abc161_bttps://atcoder.jp/contests/abc161/tasks/abc161_a
# -*- coding: utf-8 -*-
N,M = map(int,input().split())
A = input().split()
A = [int(i) for i in A]
goukei = sum(A)
ikiti = 1/(4*M)
A.sort(reverse=True)
for i in range(len(A)):
  if A[i] < goukei*ikiti:
    A[i] = "nasi"
A = [i for i in A if i != "nasi"]
if len(A) >= M:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n) for(int i = 0; i < (n); i++)
const int MOD = 1e9+7;
int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct Edge{int to,weight;};
/*----------------------------------------------*/
int dp[100005];
int h[100005];
signed main(){
  int n;
  cin>>n;
  rep(i,n)cin>>h[i];
  dp[1]=abs(h[1]-h[0]);
  FOR(i,2,n-1){
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
  }
  cout<<dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
import itertools
n, m, q = list(map(int, input().split()))
a = []
b = []
c = []
d = []
for i in range(q):
    a_, b_, c_, d_ = list(map(int, input().split()))
    a.append(a_)
    b.append(b_)
    c.append(c_)
    d.append(d_)

A = range(1, m+1)
lis = list(itertools.combinations_with_replacement(A, n))

ans = 0
for each in lis:
    tmp = 0
    for i in range(len(a)):
        if each[b[i]-1] - each[a[i]-1] == c[i]:
            tmp += d[i]

    ans = max(ans, tmp)

print(ans)


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

using namespace std;

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

	for (int i = 0; i < s.length(); i++) {
		if (s[i] == '7') {
			cout << "Yes";
			return 0;
		}
	}

	cout << "No";
}

Measured memory_bytes: 3528
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let x: i32 = sc.read();
    let a: i32 = sc.read();
    if x < a {
        println!("0");
    } else {
        println!("10");
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, num, sum;
  cin >> N;
  num = N;
  sum = 0;
  for(int i=0; 0<num; i++){
    int Si;
    Si = num%10;
    sum += Si;
    num /= 10;
  }
  
  if(N%sum == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string x,y,z;
	cin>>x>>y>>z;
	for(int i=0;i<=100;i++)	
	if(65<=(int)y[i]<=90)
{
	cout<<"A"<<y[0]<<"C\n";
	break;

}

}

Measured memory_bytes: 256
def trans(str)
    res = []
    char = str[0]
    count = 1
    1.upto(str.length - 1) do |i|
        if char == str[i]
            count += 1
        else
            res << count.to_s << char
            count = 1
            char = str[i]
        end
    end
    return (res << count << char).join("")
end

while (n = gets.to_i) != 0
    str = gets.chomp
    n.times {str = trans(str)}
    puts str
end

Measured memory_bytes: 12584
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main(){
    int n; 
    cin >> n;
    int p[30];
    for(int i = 0; i < n; i++) cin >> p[i];
    int count = 0;
    for(int i = 1; i < n-1; i++){
        if(p[i] <= p[i-1] && p[i] > p[i+1]) count++;
        else if(p[i] <= p[i+1] && p[i] > p[i-1]) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader =
                new BufferedReader(new InputStreamReader(System.in));
        int count = Integer.parseInt(reader.readLine());
        while (count-- > 0) {
            String input = reader.readLine();
            if (input == null) {
                break;
            }
            char[] temp = input.toCharArray();
            Arrays.sort(temp);
            char[] temp2 = new char[temp.length];
            for(int i = temp.length; i > 0; i--) {
                temp2[temp.length - i] = temp[i - 1];
            }
            int min = Integer.parseInt(String.valueOf(temp));
            int max = Integer.parseInt(String.valueOf(temp2));
            System.out.println(max - min);
        }
    }
}

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

const int MAXN = 1e5+5;

ll n, q, ct[MAXN], ans[MAXN];

vector<ll> p;

int main() {
	cin >> n >> q;
	p.push_back(n);
	for (int i = 0; i < q; ++i) {
		ll x; cin >> x;
		while (p.size() > 0 && p.back() >= x)
			p.pop_back();
		p.push_back(x);
	}

	ct[p.size()-1] = 1;
	for (int i = p.size()-1; i >= 0; --i) {
		ll x = p[i];
		while (x > p[0]) {
			int t = lower_bound(p.begin(), p.end(), x)-p.begin()-1;
			ct[t] += ct[i]*(x/p[t]);
			x %= p[t];
		}

		ans[x] += ct[i];
	}
	
	for (int i = n-1; i >= 1; --i)
		ans[i] += ans[i+1];
	for (int i = 1; i <= n; ++i)
        cout << ans[i] << "\n";
}

Measured memory_bytes: 4212
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);
  
  int a,b,c,d; cin >> a >> b >> c >> d;
  if ((abs(a-b)<=d && abs(b-c)<=d) || abs(a-c)<=d)
  {cout << "Yes" << endl;}
  else {cout << "No" << endl;}

  return 0;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
A=list(map(lambda x:x//400 if x<3200 else 8,A))
n_red=A.count(8)
red_exist=1 if n_red else 0
red_only=1 if red_exist and len(list(set(A)))==1 else 0
n_min=len(set(A)) if not red_exist else len(set(A))-1
print(1 if red_only else n_min,n_min+n_red)


Measured memory_bytes: 3064
using System;

namespace AtCoderABC129A
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;

            string[] s = Console.ReadLine().Split(' ');

            int[] X = new int[3];

            for (int i = 0; i < 3; i++)
            {
                X[i] = int.Parse(s[i]);
            }

            Array.Sort(X);

            ans = X[0] + X[1];

            Console.WriteLine(ans.ToString());
        }
    }
}


Measured memory_bytes: 13140
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1e9 + 7;

int fact(int n){

    int ans = 1;

    for(int i=1; i<=n; i++) {
        ans = ((ans%N)*(i%N)%N);
    }

    return ans;
}

int power(int a,int b,int m){
     int res=1;
    while(b!=0){
       
        if(b&1){
            res=(res*a)%m;
        }
        a=(a*a)%m;
        b=b>>1;
    }
    return res%m;
}

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    cin>>n;

    if(n <=1){

        cout<<0<<endl;
        return;
    }

    ans = power(10 , n , N );

    // ans= (ans%N*(n - 1)%N*(n)%N)%N;

    // ans /=2; 

    // ans -= power(8 , n , N);
    ans = (ans%N -power(9 , n , N)%N + N )%N;
    ans = (ans%N -power(9 , n , N)%N + N )%N;
    ans = (ans%N +power(8 , n , N)%N + N )%N;
    // ans = (ans%N*2)%N;
    cout<<ans<<endl;

    

}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Measured memory_bytes: 3652
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
a,b,c = c[1],c[2],c[3]
DP = [[[0]*(n+2) for i in range(n+2)] for j in range(n+2)]

for i in range(c+1):
    for j in range(n-a-i+1):
        for k in range(n-i-j+1):
            if i+j+k:
                DP[i][j][k] = (i*DP[i-1][j+1][k] + j*DP[i][j-1][k+1] + k*DP[i][j][k-1] + n)/(i+j+k)
print(DP[c][b][a])

Measured memory_bytes: 512520
using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		while(true){
			String s="";
			while(String.IsNullOrEmpty(s))s=Console.ReadLine();
			var d=int.Parse(s);
			if(d==0)break;
			Sol mySol =new Sol(d);
			mySol.Solve();
		}
	}
}

class Sol{
	public void Solve(){
		
		long mod=10007;
		int[] used=new int[N];//0-initialized;
		long ret=1;
		
		for(int i=0;i<N;i++){
			if(used[i]==0){
				long cnt=0;
				int max=0;
				used[i]=1;
				Queue<int> Q=new Queue<int>();
				Q.Enqueue(i);
				while(Q.Count>0){
					int q=Q.Dequeue();
					for(int j=0;j<2;j++){
						if(E[q][j].Cost>max){
							cnt=1;max=E[q][j].Cost;
						}else if(E[q][j].Cost==max){
							cnt++;
						}
						if(used[E[q][j].To]==0){
							used[E[q][j].To]=1;
							Q.Enqueue(E[q][j].To);
						}
					}
				}
				
				ret*=cnt/2;
				ret%=mod;
			}
		}
		
		Console.WriteLine("{0}",ret);
	}
	
	int N;
	List<Edge>[] E;
	public Sol(int n_){
		N=n_;
		E=new List<Edge>[N];
		for(int i=0;i<N;i++){
			E[i]=new List<Edge>();
			var d=ria();
			E[i].Add(new Edge(d[0],d[1]));
			E[i].Add(new Edge(d[2],d[3]));
		}
	}


	class Edge{
		public int To;
		public int Cost;
		public Edge(int t_,int c_){
			To=t_;Cost=c_;
		}
	}


	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

Measured memory_bytes: 8404
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string.h>

using namespace std;

int main(void)
{
	char n[3];
	cin >> n;
	int i;
	for (i = 0; i < strlen(n); i++)
	{
		if (n[i] == '9')
		{
			cout << "Yes" << endl;
			break;
		}
	}
	if (i == strlen(n))
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (ll)4e18;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	int red = 0, blue = 0;
	rep(i, n) {
		if (s[i] == '0') red++;
		else blue++;
	}
	cout << 2 * min(red, blue) << endl;
	return 0;
}


Measured memory_bytes: 512
q=int(input())
LR=[[int(i) for i in input().split()] for _ in range(q)]
sosu=[False]*(10**5+1)
question=[0]*(10**5+1)
for i in range(2,10**5+1):
    for j in range(2,int(i**0.5)+1):
        if i%j==0:
            break
    else:
        sosu[i]=True
for i in range(3,10**5+1):
    if sosu[i] and sosu[(i+1)//2]:
        question[i]=1
for i in range(1,10**5+1):
    question[i]+=question[i-1]
for l,r in LR:
    print(question[r]-question[l-1])

Measured memory_bytes: 69336
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    
    
    
    int main() {
   
     int n,m;
     
     cin >> n >> m;
     int a[n][m] = {0};
     int b[m] = {0};
     rep(i,n){
     	rep(j,m){
        	cin >> a[i][j];
        	
        }
     }
     
     rep(i,m){
     	cin >> b[i];
     }
     
     rep(i,n){
     	int ans = 0;
     	rep(j,m){
     		ans = ans + (a[i][j]*b[j]);
     		
     	}
     	cout << ans << '\n';
     }
     
     return 0;
    }


Measured memory_bytes: 3112