akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  vector<vector<int>> A(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int N;
  cin >> N;
  
  vector<int> B(N);
  
  for(int k = 0; k < N; k++) {
    cin >> B.at(k);
  }
  
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for(int k = 0; k < N; k++) {
        if (A.at(i).at(j) == B.at(k))
        {A.at(i).at(j) = 0;}
      }
    }
  }
  bool bingo = false;
  if (A.at(0).at(0)+A.at(1).at(1)+A.at(2).at(2) == 0) {bingo = true;}
  else if (A.at(0).at(2)+A.at(1).at(1)+A.at(2).at(0) == 0) {bingo = true;}
  else if (A.at(0).at(0)+A.at(0).at(1)+A.at(0).at(2) == 0) {bingo = true;}
  else if (A.at(1).at(0)+A.at(1).at(1)+A.at(1).at(2) == 0) {bingo = true;}
  else if (A.at(2).at(0)+A.at(2).at(1)+A.at(2).at(2) == 0) {bingo = true;}
  else if (A.at(0).at(0)+A.at(1).at(0)+A.at(2).at(0) == 0) {bingo = true;}
  else if (A.at(0).at(1)+A.at(1).at(1)+A.at(2).at(1) == 0) {bingo = true;}
  else if (A.at(0).at(2)+A.at(1).at(2)+A.at(2).at(2) == 0) {bingo = true;}
  else {bingo = false;}
  if (bingo == true) {cout << "Yes" << endl;}
  if (bingo == false) {cout << "No" << endl;}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    char[] s = scanner.next().toCharArray();
    char[] t = scanner.next().toCharArray();

    System.out.println(solve(N, M, s, t));
  }

  private static long solve(int N, int M, char[] s, char[] t) {
    if (N > M) return solve(M, N, t, s);
    long gcd = gcd(N, M);
    long lsm = (long) N / gcd * M;
    for (int i = 0, j = 0; i < N && j < M; ) {
      if (s[i] != t[j]) return -1;
      i += N / gcd;
      j += M / gcd;
    }
    return lsm;
  }

  private static long gcd(long i, long j) {
    if (i > j) return gcd(j, i);
    while (i > 0) {
      long r = j % i;
      j = i;
      i = r;
    }
    return j;
  }
}


Measured memory_bytes: 26320
import java.io.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        char a[]=bu.readLine().toCharArray();
        char b[]=bu.readLine().toCharArray();
        int i,c=0;
        for(i=0;i<a.length;i++)
        if(a[i]!=b[i]) c++;
        System.out.print(c);
    }
}


Measured memory_bytes: 37328
#include <bits/stdc++.h>
using namespace std;
#define max 1e9+7
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n;
    cin>>n;

    vector<long long> a(n);
    vector<long long> dp(n, max);
    dp[0]=0;
    
    for(long long i=0; i<n; i++) 
        cin>>a[i];
    for(long long i=0; i<n; i++){
        for(long long j=i+1; j<=i+2; j++){
            if(j<n){
                dp[j] = min(dp[j], dp[i] + abs(a[i]-a[j]));
            }
        }
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1792
def agc_027_a
    n,x = gets.chomp.split(/\s/).map{|y| y.to_i}
    an = gets.chomp.split(/\s/).map{|y| y.to_i}.sort

    cnt = 0
    for i in 1..(n-1)
        if an[i-1] <= x
            x -= an[i-1]
            cnt += 1
        end
    end
    cnt += 1 if an[-1] == x

    puts cnt
end

agc_027_a

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

bool check(string s)
{
    int r=0;
    bool f = false;
    for(int i=0;i<s.size();i++)
    {
        if(s[i] >= 'A' && s[i]<='Z')r++;
        if(s[i] == 'C' && i>1 && i <= s.size()-2)f = true;
    }
    if(r==2 && f == true)return true;
    return false;
}
int main()
{
    string s;
    cin>>s;
    if(s[0] != 'A' || !check(s))puts("WA");
    else puts("AC");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<int>a(n);
  for (auto& x : a) std::cin >> x;
  auto yes = [&] {
    std::cout << "YES" << std::endl;
    exit(0);
  };
  if (std::is_sorted(a.begin(), a.end())) yes();
  auto check = [&] (int i, int j) {
    assert(0 <= i && i < j && j < n);
    auto b = a;
    std::swap(b.at(i), b.at(j));
    if (std::is_sorted(b.begin(), b.end())) yes();
  };
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      check(i, j);
    }
  }
  std::cout << "NO" << std::endl;
  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++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<typename T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b){ if(a>b){ a=b; return 1;} return 0;}


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n; cin >> n;
    int cnt = 0;
    for(int i = n; i >= 1; i--){
        string s = to_string(i);
        if(s.size()%2==1) cnt++;
    }
    cout << cnt << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int a,b,t; cin >>a >>b >>t;
  cout <<t/a*b;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

Measured memory_bytes: 3600
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {
	 public static void main(String[] args) {
		 try (Scanner sc = new Scanner(System.in)) {
			 /* 完品トランプcardsの生成 */
			 String[] ptn = {"S ","H ","C ","D "};
			 List<String> cards = new ArrayList<String>(52);
			 for(int i = 0; i < 4; i++) {
				 for(int j = 1; j <=13 ; j++) {
					 cards.add(ptn[i] + j);
				 }
			 }
			 /* 完品トランプの生成ここまで */

			 // 入力1行目入力カード総数の読み込み, 改行文字空読み
			 int num = sc.nextInt();
			 sc.nextLine();

			 // 完品トランプから, 入力のカードを削除
			 for(int i = 0; i<num; i++) {
				 String cd = sc.nextLine();
				 cards.remove(cd);
			 }

			 // 入力カード削除後のcardsの出力
			 for (String str : cards) {
			    System.out.println(str);
			 }
		 }
	 }
}


Measured memory_bytes: 26372
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
map<int,int> pos;
int n;
int a[maxn];
bool check(int mxnum)
{
	pos.clear();
	for(int i=0;i<n;i++)
	{
		if(!i||a[i]>a[i-1])continue;
		int here=a[i];
		while(here>=1&&pos.count(here)&&pos[here]==mxnum-1)
		{
			pos.erase(here);
			here--;
		}
		if(here<1)return 0;
		if(!pos.count(here))pos[here]=1;
		else pos[here]++;
		if(pos[here]>=mxnum)return 0;
		for(map<int,int>::iterator it=pos.begin();it!=pos.end();)
			if(it->first>here)
			{
				map<int,int>::iterator tmp=it;
				it++;
				pos.erase(tmp);
			}
			else it++;
	}
	return 1;
}
int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	int l=0,r=n;
	while(r-l>1)
	{
		int mid=(l+r)>>1;
		if(check(mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int  n,a[101],s,m;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];s+=a[i];
	}
	m=s/n;
	if((s-m*n)*2>=n)m++;
	s=0;
	for(int i=1;i<=n;i++){
		s+=(a[i]-m)*(a[i]-m);
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	vector<int> x, y;
	rep(i, 0, N) {
		int tmp;
		cin >> tmp;
		x.push_back(tmp);
	}
	rep(i, 0, M) {
		int tmp;
		cin >> tmp;
		y.push_back(tmp);
	}

	vsort(x);
	vsort(y);
	int rsl = x[N - 1] + 1;
	if(X < rsl and rsl <= Y) {

		if(y[0] < rsl) {
			cout << "War" << endl;
			return 0;
		}

		cout << "No War" << endl;
		return 0;
	}

	cout << "War" << endl;



}


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

using namespace std;



int e[2010][2010], ans[2010];

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            e[j][i] = e[i][j] = j - i;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            e[i][j] = e[j][i] = min(e[i][x] + e[y][j] + 1, e[i][j]);
        }
    }
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; ++j)
            ans[e[i][j]]++;
    for (int i = 1; i < n; i++)
        cout << ans[i] << endl;
    //system("pause");
    return  0;
}

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

int main() {
  string s;
  cin >> s;
  int size = s.size();
  for (int i=0; i<size; i++) {
    if (i%2==0) {
      if (i==size-2 || i==size-1) cout << s.at(i) << endl;
      else cout << s.at(i);
    }
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N; cin >> N;
    vector<ll> A(N), B(N);
    rep(i,N) cin >> A.at(i);
    vector<pair<ll, ll>> plus, minus;
    ll sump = 0, summ = 0;
    rep(i,N) {
        cin >> B.at(i);
        if (B[i] > A[i]) {
            ll d = B[i] - A[i];
            minus.push_back({d, i});
            summ += d;
        } else {
            ll d = A[i] - B[i];
            plus.push_back({d, i});
            sump += d;
        }
    }
    if (plus.size() == N) {
        cout << 0 << endl;
        return 0;
    } else if (sump < summ) {
        cout << -1 << endl;
        return 0;
    }

    sort(plus.begin(), plus.end(), greater<pair<ll,ll>>());
    sort(minus.begin(), minus.end());

    ll i = 0, cnt = 0;
    while (!minus.empty()) {
        cnt++;
        ll m = minus.back().first; minus.pop_back();
        while (plus[i].first <= m) {
            m -= plus[i].first;
            i++;
        }
        plus[i].first -= m;
    }
    cout << i + cnt + 1 << endl;
}


Measured memory_bytes: 7056
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static java.lang.Math.sin;
import static java.lang.Math.cos;
import static java.lang.Math.toRadians;

public class Main {

  private static StringBuilder buf = new StringBuilder();

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt( br.readLine() );
      Point2D p1 = new Point2D(0,0);
      Point2D p2 = new Point2D(100, 0);

      calcKochCurve(n, p1, p2);
      System.out.print(buf);
      
    }
  }

  private static void calcKochCurve(int d, Point2D p1, Point2D p2) {
    double rad = toRadians(60);

    buf.append(p1);
    kochCurve( d, p1, p2, rad );
    buf.append(p2);
  } 

  private static void kochCurve(int d, Point2D p1, Point2D p2, double rad) {
    if( d != 0) {
      Point2D s = new Point2D();
      Point2D t = new Point2D();

      s.x = (2*p1.x + p2.x) / 3;
      s.y = (2*p1.y + p2.y) / 3;
      t.x = (p1.x + 2*p2.x) / 3;
      t.y = (p1.y + 2*p2.y) / 3;

      Point2D u = new Point2D();

      u.x = (t.x - s.x)*cos(rad) - (t.y - s.y)*sin(rad) + s.x;
      u.y = (t.x - s.x)*sin(rad) + (t.y - s.y)*cos(rad) + s.y;

      kochCurve(d-1, p1, s, rad);
      buf.append(s);
      kochCurve(d-1, s, u, rad);
      buf.append(u);
      kochCurve(d-1, u, t, rad);
      buf.append(t);
      kochCurve(d-1, t, p2, rad);
    }
  }
}

class Point2D {
  double x;
  double y;

  public Point2D() { }
  public Point2D(double x,double y) {
    this.x = x;
    this.y = y;
  }

  @Override
  public String toString() {
    return String.format("%.8f %.8f\n", x, y);
  }
  public double distance(Point2D p) {
    return Math.sqrt(Math.pow((p.x - this.x),2) + Math.pow((p.y - this.y), 2));
  }
}


Measured memory_bytes: 40444
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define pic pair<ll,char>
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii > 
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll dp[101][100001];
ll wt[101];
ll value[101];
ll n,w;
ll func(ll index,ll done)
{
    if(done>w)
        return -1e18;
    if(index==n)
        return 0;
    ll &ret = dp[index][done];
    if(ret!=-1)
        return ret;
    ret = func(index+1,done);
    ret = max(ret,value[index]+func(index+1,done+wt[index]));
    return ret;
}
signed main()
{
    fast;
    cin>>n>>w;
    mem(dp,-1);
    ll i;
    for(i=0;i<n;i++)
        cin>>wt[i]>>value[i];
    cout<<func(0,0);
}

Measured memory_bytes: 79232
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

n = inp[0]
a = inp
t = na(3)
a.each do |d|
  if(d%4 == 0)
    t[2] += 1
  elsif(d%2 == 0)
    t[1]+=1
  else
    t[0]+=1
  end
end
if(t[1] > 0)
  puts (t[0] <= t[2])? "Yes" : "No"
else
  puts (t[0] <= t[2] + 1)? "Yes" : "No"
end

Measured memory_bytes: 9492
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for(int i=0; i<m; ++i)
        cin >> x[i];
    sort(x.begin(), x.end());

    vector<int> v(m-1);
    for(int i=0; i<m-1; ++i)
        v[i] = x[i+1] - x[i];
    sort(v.begin(), v.end());

    long long ans = 0;
    for(int i=0; i<m-n; ++i)
        ans += v[i];
    cout << ans << endl;

    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int a[100002], b[100002], c[100002];
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    int dpa[100002], dpb[100002], dpc[100002];
    dpa[0] = a[0];
    dpb[0] = b[0];
    dpc[0] = c[0];
    for(int i = 1; i < n; i++){
        dpa[i] = max(dpb[i - 1], dpc[i - 1]) + a[i];
        dpb[i] = max(dpc[i - 1], dpa[i - 1]) + b[i];
        dpc[i] = max(dpa[i - 1], dpb[i - 1]) + c[i];
    }
    cout << max(dpa[n - 1], max(dpb[n - 1], dpc[n - 1])) << endl;
}

Measured memory_bytes: 2560
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
using namespace std;


int main() {
    int a, b, c;
    set<int> s;
    cin >> a >> b >> c;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    cout << s.size() << endl;
}

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

using namespace std;

const int Nmax = 5005, inf = 1e9;

int i, n, dad[Nmax], dp[Nmax], old[Nmax], Val[Nmax], best[Nmax];
vector<int> v[Nmax];

bool dfs(int node)
{
    for(auto son : v[node])
        if(!dfs(son)) return 0;

    int i;
    dp[0] = 0;
    for(i=1; i<=Val[node]; ++i) dp[i] = inf;

    for(auto son : v[node])
    {
        memcpy(old, dp, sizeof(dp));

        for(i=Val[node]; i>=0; --i)
        {
            dp[i] = inf;
            if(i >= best[son]) dp[i] = min(dp[i], old[i - best[son]] + Val[son]);
            if(i >= Val[son] ) dp[i] = min(dp[i], old[i - Val[son]] + best[son]);
        }
    }

    best[node] = inf;
    for(i=0; i<=Val[node]; ++i) best[node] = min(best[node], dp[i]);

    return (best[node] < 1e8);
}

int main()
{
 ///   freopen("input", "r", stdin);
    cin >> n;
    for(i=2; i<=n; ++i)
    {
        cin >> dad[i];
        v[dad[i]].push_back(i);
    }

    for(i=1; i<=n; ++i) cin >> Val[i];
    cout << (dfs(1) ? "POSSIBLE" : "IMPOSSIBLE") << '\n';

    return 0;
}


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

int main(){
    string a,b;
    cin>>a>>b;
    int A=a.size();
    int B=b.size();
    if(A>B){
       cout<<"GREATER"<<endl;
    }else if(A<B){
       cout<<"LESS"<<endl;
    }else{
        if(a>b){
            cout<<"GREATER"<<endl;
        }else if(a<b){
            cout<<"LESS"<<endl;
        }else{
            cout<<"EQUAL"<<endl;
        }
   }
}


Measured memory_bytes: 256
N = int(input())
S = input()
R = [0]*N
G = [0]*N
B = [0]*N
ans = 0
for i in range(N):
    R[i] = R[i-1]
    G[i] = G[i-1]
    B[i] = B[i-1]
    if S[i] == 'R':
        R[i] += 1
    elif S[i] == 'G':
        G[i] += 1
    else:
        B[i] += 1
for i in range(N):
    for k in range(i,N):
        if (S[i] != S[k]) and (S[i] != 'R' and S[k] != 'R'):
            ans += R[N-1] - R[k]
            if k+(k-i) < N and S[k+(k-i)] == 'R':
                ans -= 1
        if (S[i] != S[k]) and (S[i] != 'G' and S[k] != 'G'):
            ans += G[N-1] - G[k]
            if k+(k-i) < N and S[k+(k-i)] == 'G':
                ans -= 1
        if (S[i] != S[k]) and (S[i] != 'B' and S[k] != 'B'):
            ans += B[N-1] - B[k]
            if k+(k-i) < N and S[k+(k-i)] == 'B':
                ans -= 1
print(ans)

Measured memory_bytes: 68880
import random
D = int(input())
C = input().split()
C = [int(c) for c in C]
S = []
for i in range(D):
  s = input().split()
  s = [int(j) for j in s]
  S.append(s)
#T = [1,17,13,14,13]
T = [10] * D
def value():
  M = 0
  last = [0] * 26
  for d in range(1,D+1):
    N = 0
    t = T[d-1]
    last[t-1] = d
    #print(last)
    for j in range(26):
      N = N + C[j]*(d-last[j])
    M = M + S[d-1][t-1] - N
  return(M)
Vmax = value()
#print(Vmax)
Q = []
for i in range(1000):
  Q.append([random.randint(1,D), random.randint(1,26)])
for i in range(1000):
  Tprev = T
  T[Q[i][0]-1] = Q[i][1]
  V = value()
  if V > Vmax:
    Vmax = V
  else:
    T = Tprev
  #print(Vmax)
#print(T)
for t in T:
  print(t)

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

using namespace std;

typedef long long LL;

const int N = 1010;

int n, m;
char g[N][N];
bool st[N][N];

int main()
{
    cin >> n >> m;
    for(int i = 0; i < n; i++) cin >> g[i];

    //row
    for(int i = 0; i < n; i++)
    {
        bool w = true;
        for(int j = 0; j < m; j++)
            if(g[i][j] == '#')
                w = false;
        if(w)
        {
            for(int j = 0; j < m; j++)
                st[i][j] = true;
        }
    }

    //col
    for(int i = 0; i < m; i++)
    {
        bool w = true;
        for(int j = 0; j < n; j++)
            if(g[j][i] == '#')
                w = false;
        if(w)
        {
            for(int j = 0; j < n; j++)
                st[j][i] = true;
        }
    }

    for(int i = 0; i < n; i++)
    {
        bool p = false;
        for(int j = 0; j < m; j++)
            if(!st[i][j])
            {
                cout << g[i][j];
                p = true;
            }
        if(p) puts("");
    }

    return 0;
}


Measured memory_bytes: 384
import java.io.*;

class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		int x,y,tmp;

		do{
			String str=br.readLine();
			String[] num=str.split(" ");
			x=Integer.parseInt(num[0]);
			y=Integer.parseInt(num[1]);
			if(x==0&&y==0){
				break;
			}
			sb.append(x < y ? x + " " + y : y + " " + x).append("\n");
		}while(x!=0||y!=0);
		System.out.print(sb);
	}
}

Measured memory_bytes: 26788
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

const int N = (int) 2e5 + 5, mod = (int) 0;
int a[N], b[N], mark[N];
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> b[i];
    for (int i = 0; i < n; ++i) {
        if (i == 0 || a[i] != a[i - 1]) {
            mark[i] = 1;
            if (b[i] < a[i]) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    for (int i = n - 1; i >= 0; --i) {
        if (i == n - 1 || b[i] != b[i + 1]) {
            mark[i] = 1;
            if (a[i] < b[i]) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    int res = 1, m = (int) 1e9 + 7;
    for (int i = 0; i < n; ++i) {
        if (!mark[i]) {
            res = res * 1ll * min(a[i], b[i]) % m;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 1408
#include <stdio.h>
int main(){
  int A[100], N, i, j, swap, mini, count = 0, han;
  scanf("%d", &N);
  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
  }
  for(i = 0; i < N - 1; i++){
    han = 0;
    mini = i;
    for(j = i; j < N; j++){
      if(A[j] < A[mini]){
	mini = j;
	han = 1;
      }
    }
    if(han == 1){ 
    swap = A[i];
    A[i] = A[mini];
    A[mini] = swap;
    count++;
    }
  }
    for(i = 0; i < N; i++){
      printf("%d", A[i]);
      if(i < (N - 1))printf(" ");
  }
    printf("\n%d\n", count);

  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
using namespace std;
int main()
{
    int L;
    cin >> L;
    int N = (int)log2(L) + 1;
    vector<tuple<int, int, int>> v;
    for (int i = 1; i <= N-1; i++) {
        v.push_back(make_tuple(i, i+1, 0));
        v.push_back(make_tuple(i, i+1, 1<<(N-1-i)));
    }
    int bit = 1 << (N - 1);
    int pos = 1;
    int curr = 1 << (N - 1);
    int rest = L - (1 << (int)log2(L));
    while (bit) {
        if (rest & bit) {
            v.push_back(make_tuple(1, pos, curr));
            curr += 1 << (N-pos);
        }
        pos++;
        bit >>= 1;
    }
    cout << N << " " << v.size() << endl;
    for (auto tup : v) {
        int u, v, w;
        tie(u, v, w) = tup;
        cout << u << " " << v << " " << w << endl;
    }
    return 0;
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int N = sc.nextInt();
        int M = sc.nextInt();
        for(int i=0;i<M;i++){
            ans+=sc.nextInt();
        }
        if(ans>N){
            System.out.println(-1);
        }else{
            
            System.out.println(N-ans);
        }
    }

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


Measured memory_bytes: 46196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1000000007;
ll dp[2005][2005];
int a[2005],b[2005];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
        scanf("%d",&a[i]);
    for(int i=1; i<=m; i++)
        scanf("%d",&b[i]);
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
           dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%mod;
            if(a[i]==b[j])
                dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%mod;


        }
    }

    printf("%lld\n",(dp[n][m]%mod+1+mod)%mod);
    return 0;
}


Measured memory_bytes: 31616
mod=2019
a=input()

N=len(a)
t=[0]*mod
t[0]=1

w=1
u=0

for i in range(N):
  u=int(a[N-1-i]) * w + u
  v=u % mod
  t[v] += 1
  w *=10
  w %= mod

ans=0
for i in t:
  ans += (i-1)*i//2

print(ans)

Measured memory_bytes: 9376
#include<cstdio>
using namespace std;

int main(void) {
	int r, D, x2000;
	scanf("%d %d %d", &r, &D, &x2000);
	int nextX = x2000;
	for (int i = 0; i < 10; i++) {
		nextX = r * nextX - D;
		printf("%d\n", nextX);
	}
	return 0;
}


Measured memory_bytes: 1704
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int main()
{
	char s[19];
	cin >> s;
	for(int i=0;i<19;i++)
	{
		if(s[i]!=',')
			cout << s[i];
		else
			cout << " ";
	}
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;

struct Point {
    int x;
    int y;
}

struct Rect {
    Point start;
    Point end;
}

void main() {
    
    // input
    int m, n, k;
    {
        auto temp = readln.split;
        m = to!int(temp[0]);
        n = to!int(temp[1]);
    }
    k = to!int(readln.chomp);
    
    int[][] jungle, ocean, ice;
    jungle.length = m;
    ocean.length = m;
    ice.length = m;
    
    for(int i=0; i<m; ++i) {
        jungle[i].length = n;
        ocean[i].length = n;
        ice[i].length = n;
    }
    
    for(int i=0; i<m; ++i) {
        auto str = readln.chomp;
        for(int j=0; j<n; ++j) {
            final switch(str[j]) {
                case 'J':
                    jungle[i][j] = j == 0 ? 1 : jungle[i][j - 1] + 1;
                    ocean[i][j] = j == 0 ? 0 : ocean[i][j - 1];
                    ice[i][j] = j == 0 ? 0 : ice[i][j - 1];
                    break;
                
                case 'O':
                    jungle[i][j] = j == 0 ? 0 : jungle[i][j - 1];
                    ocean[i][j] = j == 0 ? 1 : ocean[i][j - 1] + 1;
                    ice[i][j] = j == 0 ? 0 : ice[i][j - 1];
                    break;
                
                case 'I':
                    jungle[i][j] = j == 0 ? 0 : jungle[i][j - 1];
                    ocean[i][j] = j == 0 ? 0 : ocean[i][j - 1];
                    ice[i][j] = j == 0 ? 1 : ice[i][j - 1] + 1;

                    break;
            }
        }
    }
    
    Rect[] r;
    r.length = k;
    
    for(int i=0; i<k; ++i) {
        auto temp = readln.split;
        r[i].start.x = to!int(temp[0]) -1;
        r[i].start.y = to!int(temp[1]) -1;
        r[i].end.x = to!int(temp[2]) -1;
        r[i].end.y = to!int(temp[3]) -1;
    }
    
    // calc
    for(int i=0; i<k; ++i) {
        int jungleNum, oceanNum, iceNum;
        
        for(int x=r[i].start.x; x<=r[i].end.x; ++x) {
            int startY = r[i].start.y, endY = r[i].end.y;
            jungleNum += jungle[x][endY] - (startY == 0 ? 0 : jungle[x][startY - 1]);
            oceanNum += ocean[x][endY] - (startY == 0 ? 0 : ocean[x][startY - 1]);
            iceNum += ice[x][endY] - (startY == 0 ? 0 : ice[x][startY - 1]);
        }
        
        // output
        writefln("%d %d %d", jungleNum, oceanNum, iceNum);
    }
    
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

string s;
int n;
vector<int> v;

int main(){
  cin>>s;
  n=s.size();
  if(s[n-1]=='1' | s[0]=='0'){
    cout<<-1<<endl;
    return 0;
  }
  REP(i,n-1){
    if(s[i] != s[n-2-i]){
      cout<<-1<<endl;
      return 0;
    }
  }
  FOR(i,0,n/2){
    if(s[i] == '1')
      v.push_back(i);
  }
  if(v.size()==0){
    REP(i,n-1)
      cout<<i+1<<" "<<n<<endl;
    return 0;
  }

  string s_out="";
  int par,init=1;
  REP(i,v.size()){
    par = v[i]+1;
    FOR(j,init,par){
      s_out += to_string(j) + " " + to_string(par) + "\n";
    }
    if(i!=v.size()-1)
      s_out += to_string(par) + " " + to_string(v[i+1]+1) + "\n";
    else
      s_out += to_string(par) + " " + to_string(n) + "\n";
    init = v[i]+2;
  }

  FOR(i,init,n)
    s_out += to_string(i) + " " + to_string(n) + "\n";
  
  cout<<s_out;
  return 0;
}


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

#define ll long long
#define vec vector<ll>
#define sortv(a); sort(a.begin(), a.end());
#define rev(a); reverse(a.begin(), a.end());
#define FOR(i,a,b) for (ll i = (ll)(a); i < (b); i++)
#define ROF(i,a,b) for (ll i = (ll)(b)-1; i >= (a); i--)

ll MOD = 1000000007;
ll INF = 1LL << 60;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	ll n;cin>>n;
	vec a (n);
	map<ll,ll> mp;
	FOR(i,0,n) {
		cin>>a[i];
		mp[a[i]]++;
	}
	ll good = 0;
	for (const auto pair:mp) {
		ll k = pair.second;
		if (k>=2) {
			good += k*(k-1)/2;
		}
	}
	FOR(i,0,n) {
		ll ans = good;
		ll k = mp[a[i]];
		ans -= k*(k-1)/2;
		ans += (k-1)*(k-2)/2;
		cout<<ans<<'\n';
	}
}

Measured memory_bytes: 11136
#include<stdio.h>

int Count(int n) {
	int cnt = 0;
	int N = n;
	while (N != 0) {
		cnt += N % 10;
		N /= 10;
	}
	return cnt;
}

int main() {
	int N;
	int cnt = 0, min = 1000000;
	scanf("%d", &N);

	for (int i = 1; i < N; i++) {
		cnt = Count(i) + Count(N - i);
		if (min > cnt)min = cnt;
	}
	printf("%d\n", min);



	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){

int a,b;
cin>>a>>b;

if(a >= 13)
cout<< b <<endl;
else if(a <= 5)
cout<< 0 <<endl;
else 
cout<< b/2 <<endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100009
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f;

LL h[N];
LL n, a, b;

bool judge(LL mid)
{
    LL ans = mid;
    for(int i = 1; i <= n; i++)
    {
        LL tm = h[i] - b*mid;
        if(tm > 0)
        {
            LL cnt = tm / (a - b) + (tm % (a - b) == 0 ? 0 : 1);
            ans -= cnt;
            if(ans < 0) return false;
        }
    }
    return true;
}

int main()
{
    scanf("%lld%lld%lld", &n, &a, &b);
    for(int i = 1; i <= n; i++) scanf("%lld", &h[i]);
    LL l = 0, r = INF;
    LL ans = INF;
    while(l <= r)
    {
        LL mid = (l + r)>>1;
        if(judge(mid)) ans = mid, r = mid - 1;
        else l = mid + 1;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
deque<int> deq;
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

vector<int> k;

int main(){
    string s;
    cin >> s;
    int n=s.size();
    rep(i,n){
        if(i!=n-1){
            if(s[i]!=s[i+1]){
                k.push_back(i+1);
            }
        }
    }
    int p=k.size();
    int ans=INF;
    rep(i,p){
        int t=max(k[i],n-k[i]);
        ans=min(ans,t);
    }
    if(p==0){
        ans=n;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
  int i;
  long X;
  long cnt = 100;
  scanf("%ld", &X);
//   scanf("%d %d", &A, &B);
  for (i = 1; i < 10000000;i++){
    cnt *= 1.01;
    // printf("%ld %ld\n", cnt, X);
    if (cnt >= X) {
      printf("%d\n", i);
      return 0;
    }
  }
    return 0;
  }


Measured memory_bytes: 2152
n = int(input())
XY = []
for i in range(n):
    a = int(input())
    xy = []
    for j in range(a):
        x, y = map(int, input().split())
        xy.append([x, y])
    XY.append(xy)
ans = 0
for i in range(2 ** n):
    s = [0] * n
    cnt = 0
    case = True
    for j in range(n):
        if (i >> j) & 1:
            s[j] = 1
            cnt += 1
    for k in range(n):
        if s[k] == 1:
            for l in range(len(XY[k])):
                if s[XY[k][l][0] - 1] != XY[k][l][1]:
                    case = False
    if case is True:
        ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 9248
#ifdef _DEBUG
#include "bits_stdc++.h"
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i, N) for (int i = 0; i < N; i++)
int MOD = 1e9 + 7;
using ll = long long;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    //正負のリスト
    vector<int> PL, MI;
    rep(i, N) {
        cin >> A[i];
        if (A[i] > 0)PL.push_back(A[i]);
        if (A[i] < 0)MI.push_back(A[i]);
    }
    vector<ll> rp(PL.size() + 1, 1), mp(MI.size() + 1, 1);
    vector<long double> rp_log(PL.size() + 1), mp_log(MI.size() + 1);

    auto set_rui = [&]() {
        rep(i, PL.size()) {
            rp[i + 1] = (rp[i] * PL[i]) % MOD;
            rp_log[i + 1] = rp_log[i] + log(PL[i]);
        }
        rep(i, MI.size()) {
            mp[i + 1] = (mp[i] * -MI[i]) % MOD;
            mp_log[i + 1] = mp_log[i] + log(-MI[i]);
        }
    };

    //答えは正
    if (PL.size() + min(K / 2 * 2, (int) MI.size() / 2 * 2) >= K) {
        sort(PL.rbegin(), PL.rend());
        sort(MI.begin(), MI.end());
        set_rui();
        int res;
        long double max_log = -1;
        //積の絶対値が最大になる物を考える
        for (int mcou = 0; mcou <= MI.size(); mcou += 2) {
            int pcou = K - mcou;
            if (pcou > PL.size())continue;
            if (pcou < 0)break;
            if (max_log < rp_log[pcou] + mp_log[mcou]) {
                max_log = rp_log[pcou] + mp_log[mcou];
                res = (rp[pcou] * mp[mcou]) % MOD;
            }
        }
        cout << res << endl;
    } else {
        //答えは負
        //0に出来る
        if (PL.size() + MI.size() != N) {
            cout << 0 << endl;
            return 0;
        }
        sort(PL.begin(), PL.end());
        sort(MI.rbegin(), MI.rend());
        set_rui();
        int res;
        long double min_log = 1e18;
        //積の絶対値が最小になる物を考える
        for (int mcou = 1; mcou <= MI.size(); mcou += 2) {
            int pcou = K - mcou;
            if (pcou > PL.size())continue;
            if (pcou < 0)break;
            if (min_log > rp_log[pcou] + mp_log[mcou]) {
                min_log = rp_log[pcou] + mp_log[mcou];
                res = (rp[pcou] * mp[mcou]) % MOD;
                res = (MOD - res) % MOD;
            }
        }
        cout << res << endl;
    }
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
typedef vector<pi> vp;

#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF 1e9
#define modulo 1000000007
#define forn(i, n) for(int i = 0; i < (n); i++)
#define FAST ios::sync_with_stdio(false); cin.tie(NULL);
#define end1 "\n" 
#define print(x) cout << x << end1
#define debug(x) cout<< #x <<" :: "<< x <<end1;
#define debug2(x, y) cout<< #x <<" :: "<< x << "\t" << #y <<" :: "<< y <<end1;



int main(){ 
FAST;
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif

////////
int n; cin >> n;
map<int, int> m;

for(int i = 1; i <= n; i++){
    m.insert(mp(i, 0));
}

for(int i = 0, p;  i < n-1; i++){
    cin >> p;
    m[p]++; 
}
for(int i = 1; i <= n; i++) cout << (m[i]) << end1;

return 0;
}

Measured memory_bytes: 13000
function Main(input) {
    input = input.trim();
    input = input.split("\n");
    const tmp = input[1].split(" ");
    const k = parseInt(input[0],10);
    const a = parseInt(tmp[0],10);
    const b = parseInt(tmp[1],10);

    let str = 'NG';
    for (let i = a; i <= b; i++) {
        if(i % k === 0){
            str = 'OK';
            break;
        }
    }
    console.log(str);
    
}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx;
    int dy = ty - sy;
    cout << string(dx,'R') << string(dy,'U');
    cout << string(dx,'L') << string(dy,'D');
    cout << 'L' <<string(dy + 1,'U') << string(dx + 1,'R') << 'D';
    cout << 'R' <<string(dy + 1,'D') << string(dx + 1,'L') << 'U';
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    X = []
    for _ in range(n):
        x, l = map(int, input().split())
        X.append([x - l, x + l])
    X = sorted(X, key=lambda x: x[1])

    remove = 0
    prev = X[0][1]
    for i in range(1, n):
        if X[i][0] < prev:
            remove += 1
        else:
            prev = X[i][1]
    print(n - remove)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 26324
// https://atcoder.jp/contests/abc056/tasks/abc056_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  int w, a, b;

  cin >> w >> a >> b;

  cout << max(0, max(a, b) - min(a, b) - w) << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int x,y;
	
	for(;;){
		
		scanf("%d %d",&x,&y);
		
		if(x == 0 && y == 0)
			break;
	
		if(x <= y)
			printf("%d %d\n",x,y);
		else
			printf("%d %d\n",y,x);
	
	}
	return 0;
}

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

first_s = [0 for _ in range(n)]
sec_s = [0 for _ in range(n)]

for i in range(n):
	sec_s[i] = a[i] - i
	# sec_s
	first_s[i] = -i - a[i]

# print("first_s", first_s)
# print("sec_s", sec_s)

seen_first_s = {}
ans = 0
for i in range(n):
	if sec_s[i] in seen_first_s:
		ans += seen_first_s[sec_s[i]]
	seen_first_s[first_s[i]] = seen_first_s.get(first_s[i], 0) + 1
print(ans)

Measured memory_bytes: 138628
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
#define N 5000100
char a[N];
char b[N];
ll k=0;
int deal()
{
    for (ll i=0,j=k-1;i<k/2;i++,j--)
            if (b[i]!=b[j])
          return 0;
    return 1;
}

int main()
{
    int flag=0;
    scanf("%s",a);
   ll len=strlen(a);
   ll num=0;
   for (ll i=0;i<len;i++)
      if (a[i]!='x')
         b[k++]=a[i];
   if (!deal())
       flag=1;
   else
   {
       int j=len-1;
       for (ll i=0;i<j;)
       {
           if (a[i]==a[j])
            i++,j--;
           else if (a[i]=='x')
             i++,num++;
           else if (a[j]=='x')
              j--,num++;
       }
   }
   if (flag)
    cout << "-1" << endl;
   else
   cout << num << endl;

    return 0;
}


Measured memory_bytes: 2432
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>

using namespace std;

string s, t;

int main(){
	bool b = 0, c = 0;
	cin >> s >> t;
	
	for(int i = s.size(); i >= 0; i--){
		c = 0;
		if(s[i] == t[0] || s[i] == '?'){
			for(int j = 1; j < t.size(); j++){
				if(t[j] != s[i+j] && s[i+j] != '?'){
					c = 1;
					break;
				}
			}
			if(c) continue;
			for(int j = 0; j < t.size(); j++){
				s[i + j] = t[j];
			}
			b = 1;
			break;
		}
	}
	
	if(b){
		for(int i = 0; i < s.size(); i++){
			if(s[i] == '?')
				s[i] = 'a';
		}
		cout << s << endl;
	}
	else
		cout << "UNRESTORABLE" << 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++)
#define REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

vector<int> to[100005];
vector<bool> seen;

void dfs(int v){
	seen[v] = true;
	for(auto nextv: to[v]){
		if(seen[nextv]) continue;
		dfs(nextv);
	}
	return ;
}

int main(){
	int n,m;
	cin >> n >> m;
	seen.resize(n);
	rep(i,m){
		int x,y,z;
		cin >> x >> y >> z;
		x--;y--;
		to[x].push_back(y);
		to[y].push_back(x);
	}
	int ans = 0;
	rep(i,n){
		if(seen[i]) continue;
		dfs(i);
		ans++;
	}
	cout << ans << endl;
	
    return 0;
}



Measured memory_bytes: 8832
def resolve():
    ls='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    n=int(input())
    s=input()
    ans=''
    for t in s:
    	c=ls.index(t)
    	if n+c>25:
    	    n-=26
    	ans+=ls[n+c]
    print(ans)
resolve()

Measured memory_bytes: 40796
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr ll INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

vector<vector<int>> G(100010);
vector<vector<ll>> dp(100010, vector<ll>(2));

const int W = 0;
const int B = 1;

void dfs(int cv, int parent = -1){
    dp[cv][W] = dp[cv][B] = 1;

    for(auto nv : G[cv]){
        if(nv == parent) continue;

        dfs(nv, cv);
        (dp[cv][W] *= dp[nv][W] + dp[nv][B]) %= MOD;
        (dp[cv][B] *= dp[nv][W]) %= MOD;
    }

    return ;
}

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

    int n; cin>>n;
    for(int i=0; i<n-1; i++){
        int x, y; cin>>x>>y;
        x--, y--;
        G[x].emplace_back(y);
        G[y].emplace_back(x);
    }

    dfs(0);

    cout << (dp[0][W] + dp[0][B]) % MOD << endl;
}

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

int main()
{
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];

  sort(a.begin(), a.end());

  if(a[0]+a[1] == a[2]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};
	
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,x;
	cin >> n >> x;

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

	int ans=0;
	bool flag=true;
	for(int i=0;i<n;i++){
		if(a[i] <= x){
			x-=a[i];
			ans++;
			if(x==0){
				break;
			}
		}else{
			flag=false;
			break;
		}
	}
	if(flag && x!=0 && ans>0) ans--;
	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int main(){
	int N;
	cin>>N;
	int S=0,x=N;
	rep(i,10){
		if(x==0)break;
		S=S+(x%10);
		x=x/10;
	}
	if(N%S==0)cout<<"Yes";
	else cout<<"No";
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
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; }

int main()
{
	int a, b, c, d;

	cin >> a >> b >> c >> d;

	while (a > 0 || c > 0)
	{
		c -= b;
		if (c <= 0)
		{
			cout << "Yes" << endl;
			break;
		}
		
		a -= d;
		if (a <= 0)
		{
			cout << "No" << endl;
			break;
		}
	}


	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			if (x == 0 && y == 0)
				break;
		    if (x < y) {
		    	System.out.println(x + " " + y);
		    } else {
		    	System.out.println(y + " " + x);
		    }
		}
	}
}


Measured memory_bytes: 35020
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int a[4];
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  sort(a,a+4);
  if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
N,x=map(int,input().split())
A=[int(i) for i in input().split()]
A=[0]+A
ans=0
for i in range(N):
    t=A[i]+A[i+1]
    if t>x:
        ans+=t-x
        #print(i,t-x)
        A[i+1]-=t-x
print(ans)

Measured memory_bytes: 63984