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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


const int POOL_SIZE=10000000;
struct node{
    int v;
    node *l,*r;
    node(){v=0;l=r=NULL;};
}pool[POOL_SIZE];
int uku=0;
node *aloc(){
    assert(uku<POOL_SIZE);
    return &pool[uku++];
}

const int SEG=1<<18;
const int INF=1001001001001001001ll;
int N;
int A[SEG*2];
int B[SEG*2];


node *build(int k,int l,int r,int A[]){
    if(l+1==r){
        node *t=aloc();
        t->v=A[l];
        return t;
    }

    node *x=build(k*2+1,l,(l+r)/2,A);
    node *y=build(k*2+2,(l+r)/2,r,A);

    node *t=aloc();
    t->v=min(x->v,y->v);
    t->l=x;
    t->r=y;

    return t;
}

int getmin(int a,int b,node *t,int l=0,int r=SEG){
    if(r<=a||b<=l)return INF;
    if(a<=l&&r<=b)return t->v;
    return min(getmin(a,b,t->l,l,(l+r)/2),getmin(a,b,t->r,(l+r)/2,r));
}

node *update(int p,int v,node *t,int l=0,int r=SEG){

    if(!(l<=p&&p<r))return t;
    if(l+1==r){
        t=aloc();
        t->v=v;
        return t;
    }

    node *s=aloc();
    s->l=update(p,v,t->l,l,(l+r)/2);
    s->r=update(p,v,t->r,(l+r)/2,r);
    s->v=min(s->l->v,s->r->v);
    return s;
}

signed main(){
    fill_n(A,SEG,INF);
    fill_n(B,SEG,INF);
    scanf("%lld",&N);
    rep(i,N){
        scanf("%lld",&A[i]);
    }
    rep(i,N){
        scanf("%lld",&B[i]);
    }

    node *rootA=build(0,0,SEG,A);
    node *rootB=build(0,0,SEG,B);


    int Q;scanf("%lld",&Q);
    while(Q--){
        int x,y,z;
        scanf("%lld%lld%lld",&x,&y,&z);
        y--;

        if(x==1){
            rootA=update(y,z,rootA);
        }
        if(x==2){
            rootB=update(y,z,rootB);
        }
        if(x==3){
            printf("%lld\n",getmin(y,z,rootA));
        }
        if(x==4){
            printf("%lld\n",getmin(y,z,rootB));
        }
        if(x==5){
            rootA=rootB;
        }
        if(x==6){
            rootB=rootA;
        }


    }
    return 0;
}

Measured memory_bytes: 241688
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;

int main() {

	int A, B;
	cin >> A >> B;

	if (A < 2 * B) {
		cout << 0 << endl;
	}
	else {
		cout << A - 2 * B << endl;
	}
	
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    map<string , int> ans;
    string s;
    for ( int i = 0; i < N; ++i)
    {
        cin >> s;
        ans[s] += 1;
    }
    cout << ans.size() << endl;
    // vector<string> s(N);
    // for ( int i = 0; i < N; ++i)
    // {
    //     cin >> s.at(i);
    // }
    // int count = 1;
    // for ( int i = 0; i < N; ++i)
    // {
    //     for ( int j = 0; j < N; ++j)
    //     {
    //         if ( i > j ) 
    //             break;
    //         if ( s.at(i) != s.at(j) )
    //             count++;
            
    //     }
    // }
    // cout <<  count << endl;
}

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

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

ll dp[3100][3100];


int main(){
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<t.size();j++){
            if(s[i]==t[j])chmax(dp[i+1][j+1],dp[i][j]+1);
            chmax(dp[i+1][j+1],dp[i+1][j]);
            chmax(dp[i+1][j+1],dp[i][j+1]);
        }
    }

    string res="";
    int i=(int)s.size(),j=(int)t.size();
    while(i>0 && j>0){
        if(dp[i][j]==dp[i-1][j]){
            --i;
        }

        else if(dp[i][j]==dp[i][j-1]){
            --j;
        }
        else{
            res=s[i-1]+res;
            --i; --j;
        }
    }
    cout<<res<<endl;

}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i, j;
		while(true){
			int H = sc.nextInt();
			int W = sc.nextInt();
			
			if(H == 0 && W == 0) break;
			
			for(i = 0; i < H; i++){
				for(j = 0; j < W; j++){
					System.out.print("#");
				}
			System.out.println();
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 38016
public class Main{
  static int N = 1024 * 1024;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int[] p;
    int pn, i, j, n, count, l, m, r;

    p = new int[N / 6];
    pn = getprime(p);

    for(;;){
      n = sc.nextInt();
      if(n == 0)break;
      count = 0;
      for(i = 0;i < pn && p[i] <= n / 2;i++){
        l = 0; r = pn - 1;
        for(;l <= r;){
          m = (l + r) / 2;
          if(p[i] + p[m] < n)l = m + 1;
          else if(p[i] + p[m] > n)r = m - 1;
          else{ count++; break; }
        }
      }
      out.println(count);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
  private static int getprime(int[] p){
    int i, j, count = 0;
    boolean[] e;
    e = new boolean[N];
    e[0] = true; e[1] = true;
    for(i = 2;i < N;i++)if(!e[i]){
      p[count++] = i;
      for(j = i * 2;j < N;j+=i)e[j] = true;
    }
    return count;
  }
}

Measured memory_bytes: 28524
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    vector <int> d;
    cin >>n;
    int tmp;
    FOR(i,0,n){
        cin >>tmp;
        d.push_back(tmp);
    }
    sort(d.begin(),d.end());
    cout << d[n/2]-d[n/2-1];
    return 0;
}

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

int main(void){
  int i,n,ac=0,wa=0,tle=0,re=0;
  char s[10];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",s);
    if(strncmp(s,"AC",2)==0)ac++;
    if(strncmp(s,"WA",2)==0)wa++;
    if(strncmp(s,"TLE",3)==0)tle++;
    if(strncmp(s,"RE",2)==0)re++;
  }

  printf("AC x %d\n",ac);
  printf("WA x %d\n",wa);
  printf("TLE x %d\n",tle);
  printf("RE x %d\n",re);
  
  return 0;
}
    


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B, C;
    cin >> A >> B >> C;
    
    if(A == B && B == C){
        cout << "No" << endl;
    }
    else if(A == C && A != B){
        cout << "Yes" << endl;
    }
    else if(B == C && B != A){
        cout << "Yes" << endl;
    }
    else if(A == B && B != C){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=100005;
int n;
int a[MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	if(a[1]>=0)
	{
		int M=-a[1];
		for(int i=2;i<=n;i++)
			M+=a[i];
		printf("%d\n",M);
		M=a[1];
		for(int i=2;i<=n-1;i++)
		{
			printf("%d %d\n",M,a[i]);
			M-=a[i];
		}
		printf("%d %d\n",a[n],M);
	}
	else
	{
		int M=a[n];
		for(int i=1;i<n;i++)
		{
			if(a[i]<=0)
				M+=-a[i];
			else
				M+=a[i];
		}
		printf("%d\n",M);
		M=a[1];
		for(int i=1;i<n;i++)
		{
			if(a[i]>=0)
			{
				printf("%d %d\n",M,a[i]);
				M-=a[i];
			}
		}
		printf("%d %d\n",a[n],M);
		M=a[n]-M;
		for(int i=2;i<n;i++)
		{
			if(a[i]<0)
			{
				printf("%d %d\n",M,a[i]);
				M-=a[i];
			}
		}
	}
}

Measured memory_bytes: 2176
#include <iostream>

using namespace std;

int main(void)
{
	int c[3][3], a, b;

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

	a = c[0][0] - c[1][0];
	b = c[0][0] - c[2][0];
	if ((a == c[0][1] - c[1][1]) && (a == c[0][2] - c[1][2]) && (b == c[0][1] - c[2][1]) && (b == c[0][2] - c[2][2])) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

			



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++){
    a[i] = 0;
  }
    for (int i = 0; i < k; i++)
    {
      int d;
      cin >> d;
      for (int j = 0; j < d; j++)
      {
        int e;
        cin >> e;
        a[e - 1]++;
      }
    }
  int num = 0;
  for (int i = 0; i < n; i++)
  {
    if (a[i] == 0){
      num++;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  vector<Int> c(3,0);
  for(Int i=0;i<n;i++) c[a[i]%3]++;
  Int ans=0;
  if(c[1]) ans=max(ans,c[0]+1+min(c[1]-1,c[2])*2+(c[1]-1>c[2]));
  if(c[2]) ans=max(ans,c[0]+1+min(c[2]-1,c[1])*2+(c[2]-1>c[1]));
  if(ans<n) ans++;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 6792
#include <iostream>

using namespace std;
using ll = long long;
const int MX = 1000100;
ll f[MX],inv[MX],fi[MX];
constexpr ll mod = 1000000007;
void solve(){
    inv[1] = 1;
    for(int i=2;i<MX;i++){
        inv[i] = mod - (mod/i)*inv[mod%i]%mod;
    }
   f[0] = fi[0] = 1;
    for(int i=1;i<MX;i++){
        f[i] = f[i-1]*i%mod;
        fi[i] = fi[i-1]*inv[i]%mod;
    }
}

ll nck(ll n, ll k){
    if(n<0 || k<0 || n<k) return 0;
    return f[n]*fi[k]%mod*fi[n-k]%mod;
}

int main(){
    ll i,n,m; cin >> n >> m;
    solve();
    ll ans = 0;
    ll s = 1;
    for(i=0;i<=n;i++){
        ans += nck(n,i)*f[m - i]%mod*fi[m - n]%mod*s;
        while(ans<0) ans += mod;
        ans %= mod;
        s *= -1;
    }
    (ans *= f[m]*fi[m - n]%mod) %= mod;
    cout << ans << endl;
}

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

using namespace std;

vector <int> d;

int main(){
    #ifdef HOME
    	freopen("input.txt", "rt", stdin);
    #endif
    int n, m = 0;
    cin >> n;
    d.resize(n);
    for (int i = 0; i < n; i++){
    	cin >> d[i];
   		m = max(m, d[i]);
   	}
   	int ans = 0;
   	for (int i = 1; i < n; i++){
   		if (d[i - 1] == d[i]){
   			d[i] = ++m;
   			ans++;
   		}
   	}           
   	cout << ans;
	return 0;
}

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

int main() {
	int A,B;
    cin >> A >> B;
    if(A == 2 && B == 2){
      cout << "Yes" << endl;
    }
    else if ( (A == 4 || A == 6 || A == 9 || A == 11) && (B == 4 || B == 6 || B == 9 || B == 11)){
      cout << "Yes" << endl;
    }
    else if( (A == 1 || A == 3 || A == 5 || A == 7 || A == 8 || A == 10 || A == 12) && (B == 1 || B == 3 || B == 5 || B == 7 || B == 8 || B == 10 || B == 12)){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
signed main(){
    int k;
    cin>>k;
    cout<<a[k-1]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	pair<int, int> p[10000];
	for (int N, M; cin >> N >> M&&N;) {
		memset(p, 0, sizeof(p));
		for (int i = 0; i < N; i++) {
			int D, P; cin >> D >> P;
			p[i].first = P;
			p[i].second = D;
		}
		sort(p, p + 10000, greater<pair<int, int> >());

		//for (int j = 0; j < N; j++) {
		//	cout << p[j].first << " " << p[j].second << endl;
		//}

		int ans = 0;
		int i;
		for (i = 0; i < N; i++) {
			M -= p[i].second;
			if (M < 0) {
				ans += p[i].first*(-M);
				i++;
				break;
			}
		}
		for (; i < N; i++) {
			ans += p[i].first*p[i].second;
		}

		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1248
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if( b <= a && a <=c )
        cout << b << " " <<a  << " " << c << endl;
    else if( b <= c  && c <=a )
        cout << b << " " << c << " " << a << endl; 
    else if( c <= b && b <=a )
        cout << c << " " << b << " " << a  << endl;
    else 
        cout << c << " " << a << " " << b << endl;
}


Measured memory_bytes: 3068
class Node():
  def __init__(self, id):
    self.id = id
    self.parent = self.right = self.left = None
    self.depth = -1
    self.height = -1
    self.degree = -1
    self.sibiling = -1

class BinaryTree():
  def __init__(self, node_ids, child_info):
    self.root = None
    tmp = sorted(zip(node_ids, child_info), key=lambda x:x[0])
    node_ids = [x[0] for x in tmp]
    child_info = [x[1] for x in tmp]
    self.nodes = [Node(x) for x in node_ids]
    for n, c in zip(self.nodes, child_info):
      self.set_children(n, *c)
    self.set_root()
    self.set_depth(self.root, 0)
    self.set_height()
    self.set_sibilings()
  
  def set_root(self):
    for n in self.nodes:
      if n.parent is None:
        self.root = n
    
  def set_children(self, node, left, right):
    degree = 0
    if left != -1:
      node.left = self.nodes[left]
      node.left.parent = node
      degree += 1
    if right != -1:
      node.right = self.nodes[right]
      node.right.parent = node
      degree += 1
    node.degree = degree 

  def set_depth(self, node, d):
    node.depth = d
    if node.left is not None:
      self.set_depth(node.left, d + 1)
    if node.right is not None:
      self.set_depth(node.right, d + 1)
  
  def set_height(self):
    def get_height(n:Node):
      h1=0
      h2 = 0
      if n.left is not None:
        h1 = get_height(n.left) + 1
      if n.right is not None:
        h2 = get_height(n.right) + 1
      n.height = max(h1,h2)
      return max(h1,h2)
    get_height(self.root)
    
  
  def set_sibilings(self):
    for n in self.nodes:
      if n.parent is None:
        n.sibiling = -1
      else:
        if n.parent.right is not None and n.parent.right != n:
          n.sibiling = n.parent.right.id
        elif n.parent.left is not None and n.parent.left != n: 
          n.sibiling = n.parent.left.id
        else:
          n.sibiling = -1

def print_node(n: Node):
  if n.parent is None:
    ntype = "root"
  elif n.right is None and n.left is None:
    ntype = "leaf"
  else:
    ntype = "internal node"
  template = "node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}"
  parent = n.parent.id if n.parent is not None else -1
  print(template.format(n.id, parent, n.sibiling, n.degree, n.depth, n.height, ntype))


def main():
  n = int(input())
  tmp = [list(map(int, input().split())) for _ in range(n)]
  n = [x[0] for x in tmp]
  c = [x[1:] for x in tmp]
  T = BinaryTree(n,c)
  nodes = T.nodes
#  nodes = sorted(nodes, key=lambda x:x.id)
  for n in nodes:
    print_node(n)

if __name__ == "__main__":
  import sys, io

  main()




Measured memory_bytes: 5624
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
from collections import defaultdict
d = defaultdict(int)
N,M = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
for i in range(M):
    b,c = map(int,input().split())
    d[c] += b
d = dict(d)
d = sorted(d.items(),key = lambda x:x[0],reverse = True)
n = len(d)
index = 0
for i in range(n):
    d[i] = list(d[i])
D = [0] * N
index = 0
for k in range(N):
    if d[index][1] != 0:
        d[index][1] -= 1
        D[k] = d[index][0]
    else:
        index += 1
        if index  == n:
            break
        else:
            d[index][1] -= 1
            D[k] = d[index][0]  
Max = 0

for p in A:
    Max += p
for X in range(N):
    if A[X] < D[X]:
        Max += D[X] - A[X]
    else:
        break
print(Max)

Measured memory_bytes: 28576
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  int a, b;
  cin >> a >> b;
  cout << 6 - a - b << endl;
}

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		int[] l = new int[n];
		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
		}
		Arrays.sort(l);

		int sum = 0;
		for (int i = 0; i < n - 1; i++) {
			sum += l[i];
		}

		if (l[n - 1] < sum) {
			pr.println("Yes");
		} else {
			pr.println("No");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int main() {
	int x;
	cin >> x;
	vector<int> prime = { 2 };
	for (int i = 2; i < x; i++) {
		int a = 0;
		for (int j = 0; j < prime.size(); j++) {
			if (i % prime.at(j) == 0) {
				a++; 
				break;
			}
		}
		if (a == 1) continue;
		else prime.push_back(i);
	}
	if (x == 2) {
		cout << 2 << endl;
	}
	else {
		int a = x;
		while (true) {
			int b = 0;
			for (int i = 0; i < prime.size(); i++) {
				if (a % prime.at(i) == 0) {
					b++;
					break;
				}
			}
			if (b == 1) a++;
			else {
				cout << a << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    for(int i = 0; i < n - k; i++){
        if(a[i] < a[i+k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#define Z class
#define ln cout<<'\n'
#define ll long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;

int main(){
    int N,K; cin >> N >> K;
    string S; cin >> S;
    S[K-1]+=32;
    cout << S  << endl;
    
}


Measured memory_bytes: 256
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl

ll f(ll n,ll x){
    if(n==-1){
        return 0;
    }
    ll ans;
    ans=n/x;
    return ans+1;
}

int main(){
    ll a,b,x;cin >> a >> b >> x;
    ll a_b=f(b,x);
    ll a_a=f(a-1,x);
    cout << a_b-a_a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <cmath>
#include <cassert>
#include <iostream>
#include <string>
#include <map>
#define mkp make_pair
#define IOS ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=2e5+5;
const int mod=998244353;
const int INF=2147483647;
struct P{
	int x,y;
	bool operator < (const P& rhs) const{
		if(x>0 || (x==0 && y<0)){
			if(rhs.x<0 || (rhs.x==0 && rhs.y>0)) return 1;
			else{
				return (long long)y*rhs.x<(long long)x*rhs.y;
			}
		}
		else{
			if(rhs.x>0 || (rhs.x==0 && rhs.y<0)) return 0;
			else{
				return (long long)y*rhs.x<(long long)x*rhs.y;
			}
		}

	}
};
vector<P> V;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		if(x||y){
			V.push_back((P){x,y});
		}
	}
	sort(V.begin(),V.end());
	long long ans=0;
	for(int i=0;i<V.size();i++){
		long long x=V[i].x,y=V[i].y;
		ans=max(ans,x*x+y*y);
		for(int j=(i+1)%V.size();j!=i;j=(j+1)%V.size()){
			x+=V[j].x;
			y+=V[j].y;
			ans=max(ans,x*x+y*y);
		}
	}
	printf("%.20f\n",sqrt(ans));
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = n;
		int i = 0;
		double sum = 0;
		while(true) {
			sum += t % 10;
			t = t / 10;
			i++;
			if(t < 1) break;
		}
		if(n % sum == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 23764
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);

ll mod = 998244353;
template<typename T> void add(T &a,T b){a=(a+b)%mod;}
template<typename T> void sub(T &a,T b){a=(a+mod-b)%mod;}

int dp[333][333][333];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    string s;
    int k;
    cin>>s>>k;
    int n = s.size();
    int sum[n+1]={};
    int z = 0;
    int o = 0;
    for(int i=0;i<n;i++){
        if(s[i] == '0'){
            z++;
            sum[z+1] = sum[z];
        }
        else o++;
        sum[z+1] = o;
    }
    
    dp[0][0][0] = 1;
    for(int i=0;i<z;i++){
        for(int y=0;y<=min(k,o);y++){
            for(int j=sum[i];j<=min(o,sum[i]+k);j++){
                if(dp[i][j][y] == 0)continue;
                if(j-sum[i] > y)break;
                for(int p=max(j,sum[i+1]);p<=min(sum[i+1]+k,o);p++){
                    int ret = dp[i][j][y];
                    int cnt = y;
                    int dif = p - j;
                    dif -= sum[i+1] - sum[i];
                    dif = max(0,dif);
                    cnt += dif;
                    if(cnt <= k){
                        add(dp[i+1][p][cnt],ret);
                    }
                    else break;
                }
            }
        }
    }
    int ans = 0;
    for(int i=sum[z];i<=o;i++){
        for(int y=0;y<=min(o,k);y++){
            add(ans,dp[z][i][y]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 19012
/*input
8 6
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	int a,b;
	cin>>a>>b;
	cout<<max({a+b,a-b,a*b});
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
struct point
{
	int t;
	int x;
	int y;
}a[100000+10];
int main()
{
	int N;
	scanf("%d",&N);
	for(int j=1; j<=N; j++)
	{
		scanf("%d %d %d",&a[j].t,&a[j].x,&a[j].y);
	}
	int i;
	for(i=1; i<=N; i++)
	{
		if(i==1)
		{
			if(a[i].x + a[i].y == a[i].t || (a[i].t > a[i].x + a[i].y && (a[i].x + a[i].y) %2 == a[i].t%2))
				continue;
			else
			{
				printf("No\n");
				break;	
			}
		}
		else
		{
			int ans=abs(a[i].x -a[i-1].x  + a[i].y - a[i-1].y);
			if( ans== a[i].t-a[i-1].t || (a[i].t-a[i-1].t > ans && (a[i].t-a[i-1].t) % 2== ans % 2))
				continue;
			else
			{
				printf("No\n");
				break;	
			}
		}
	}
	if(i == N+1)
		printf("Yes\n");
	return 0;
}

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

int main(){
    while (1){
        string s;
        getline(cin, s);
        if (s.size() == 1 && s[0] == '.') break;
        vector<char> tmp;
        int left_round = 0;
        int left_angle = 0;

        int k = s.size();
        for (int i = 0; i < k; i++){
            if (s[i] == '('){
                tmp.push_back('(');
                left_round++;
            }
            else if (s[i] == ')'){
                if (left_round < 1 || tmp.size() < 1 || tmp.back() != '('){
                    left_round = 1;
                    break;
                }
                else {
                    left_round--;
                    tmp.pop_back();
                }
            }
            else if (s[i] == '['){
                left_angle++;
                tmp.push_back('[');
            }
            else if (s[i] == ']'){
                if (left_angle < 1 || tmp.size() < 1 || tmp.back() != '['){
                    left_angle = 1;
                    break;
                }
                else {
                    left_angle--;
                    tmp.pop_back();
                }
            }
        }
        if (left_round == 0 && left_angle == 0) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3072
from bisect import bisect_left

N = int(input())
A,c = list(range(N)),[]
for i in range(N):
	A[i] = int(input())

for x in reversed(A):
	p = bisect_left(c, x+1)
	if p == len(c):
		c.append(x)
	else:
		c[p] = x
print(len(c))

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

int main () {
    int n;
    cin >> n;
    int A[n];

    for (int i=0; i<n; i++) cin >> A[i];
    for (int i=0; i<n; i++) {
        cout << A[i];
        if (i < n-1) cout << " ";
    }
    cout << endl;
    for (int i=1; i<n; i++) {
        int cur = A[i];
        int j = i - 1;
        while (cur < A[j] && 0 <= j) {
            A[j+1] = A[j];
            j--;
        }
        A[j + 1] = cur;
        for (int i=0; i<n; i++) {
            cout << A[i];
            if (i < n-1) cout << " ";
        }
        cout << endl;
    }
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Vertex
{
    vector<pll> node;
};

Vertex V[100005];
ll S[100005];

int main()
{
    ll N, M, R;
    cin >> N >> M >> R;
    REP(i, M)
    {
        ll s, t, d;
        cin >> s >> t >> d;
        V[s].node.push_back(pll(t, d));
    }

    REP(i, N)
    {
        S[i] = INF;
    }
    priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return a.second > b.second; });
    q.push(pll(R, 0));
    while (!q.empty())
    {
        pll t = q.top();
        q.pop();
        if (S[t.first] <= t.second)
            continue;
        S[t.first] = t.second;
        REP(i, V[t.first].node.size())
        {
            pll n = V[t.first].node[i];
            ll cost = t.second + n.second;
            if (S[n.first] <= cost)
                continue;
            q.push(pll(n.first, cost));
        }
    }
    REP(i, N)
    {
        if (S[i] == INF)
            cout << "INF";
        else
            cout << S[i];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 21544
n, m = map(int, input().split())
box = [-1 for _ in range(n)]
for i in range(m):
    s, c = map(int, input().split())
    s -= 1
    if box[s] != -1 and box[s] != c:
        print(-1)
        exit()
    box[s] = c

ans = ""
if n == 1:
    if box[0] == -1:
        print(0)
    else:
        print(box[0])
    exit()

for i in range(n):
    if box[i] == -1 and i == 0:
        ans += '1'
    elif box[i] == -1:
        ans += '0'
    else:
        if i == 0 and box[i] == 0:
            print(-1)
            exit()
        ans += str(box[i])

print(ans)


Measured memory_bytes: 3064
s = input()

if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
else:
    print(1)


Measured memory_bytes: 2940
#include <cstdio>
#include <utility>
#include <cstdlib>
#include <cctype>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

struct calc {
	char c;

	calc() {
		c = gcu();
	}

	bool consume(char e) {
		if (c != e)
			return false;
		else {
			c = gcu();
			return true;
		}
	}

	int number() {
		if (isdigit(c)) {
			int d;
			ungetc(c, stdin);
			scanf("%d", &d);
			c = gcu();
			return d;
		} else {
			fprintf(stderr,"ERROR: expected number\n, but got %c\n", c);
			exit(0);
		}
	}

	int mul() {
		int a = term();
		for (;;)
			if (consume('*'))
				a *= term();
			else if (consume('/'))
				a /= term();
			else
				return a;
	}

	int add() {
		int a = mul();
		for (;;)
			if (consume('+'))
				a += mul();
			else if (consume('-'))
				a -= mul();
			else
				return a;
	}

	int term() {
		if (consume('(')) {
			int a = add();
			consume(')');
			return a;
		} else
			return number();
	}


	int exec() {
		int n = add();
		if (consume('='))
			return n;
		else {
			fprintf(stderr,"ERROR: expected =, but got %c\n", c);
			exit(0);
		}
	}
};

int main() {
	for (int n = in(); n; n--) {
		calc c = calc();
		outl(c.exec());
	}
}


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

int main(void){
    int n, m, num = 0;
    
    cin >> n >> m;
    
    vector<int> a(m+1);
    vector<long long> d(n+1);
    
    rep(i, m){
        cin >> a.at(i);
    }
    
    d.at(0) = 1;
    
    if(a.at(0) != 1){
        d.at(1) = 1;
    } else {
        num++;
    }
    
    for(int i = 2; i < n+1; i++){
        if(a.at(num) != i){
            d.at(i) = (d.at(i-1) + d.at(i-2))%1000000007;
        } else {
            num++;
        }
    }
    
    cout << d.at(n) << endl;
    
    return 0;
}

Measured memory_bytes: 1408
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    n,*a=map(int,open(0).read().split())
    p=sorted(a)
    print(p[n//2]-p[n//2-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 15992
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;

string s1, s2;
const int M = 131072;
string it[2][2*M];
int q, p1, p2, k1, k2;
vector< int > v;

string simp( string s )
{
	string ret;
	while( s.size() > 1 )
	{
		
		string ret = "";
		for( int a = 0; a < s.size(); )
		{
			
			if( a + 1 < s.size() && s[a] != s[a+1] )a += 2;
			else if( a + 1 < s.size() && s[a] == s[a+1] )
			{
				if( s[a] == 'A' )ret += 'B';
				else ret += 'A';
				a += 2;
			}
			else ret += s[a], a++;
		}
		s = ret;
	}
	return s;
}

void ins( int i, int x, char let )
{
	x += M - 1;
	it[i][x] = let;
	x /= 2;
	string st;
	while( x )
	{
		st = it[i][2*x] + it[i][2*x+1];
		st = simp( st );
		it[i][x] = st;
		x /= 2;
	} 
}
string get( int i, int pocz, int kon )
{
	string ret = "";
	v.clear();
	pocz += M - 1;
	kon += M - 1;
	v.push_back( pocz );
	if( kon != pocz )v.push_back( kon );
	while( pocz + 1 < kon )
	{
		if( pocz%2 == 0 )v.push_back( pocz+1 );
		if( kon%2 )v.push_back( kon-1 );
		pocz /= 2;
		kon /= 2;
	}
	for( int a = 0; a < v.size(); a++ )ret += it[i][v[a]];
	ret = simp( ret );
	return ret;
}
int main()
{
	ios_base::sync_with_stdio( 0 );
	cin.tie( 0 );
	cin>>s1>>s2;
	cin>>q;
	for( int a = 0; a < s1.size(); a++ )ins( 0, a+1, s1[a] );
	for( int a = 0; a < s2.size(); a++ )ins( 1, a+1, s2[a] );
	for( int a = 1; a <= q; a++ )
	{	
		cin>>p1>>k1;
		cin>>p2>>k2;
		s1 = get( 0, p1, k1 );
		s2 = get( 1, p2, k2 );
		//cout<<s1<<" "<<s2<<endl;
		if( s1 == s2 )cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	
	return 0;
}
 



Measured memory_bytes: 23532
N = int(input())
list = list(map(int, input().split()))
c = 0
b = True

while b == True:
    for i in range(0,len(list)):
        if list[i] % 2 != 0:
            b = False
        else:
            list[i] = list[i] / 2
    if b == False:
        break
    c += 1

print(c)

Measured memory_bytes: 3060
def f(n):  # 0からnまでのxor
    if n % 2 == 0:
        if (n // 2) % 2 == 0:
            return n
        else:
            return 1 ^ n
    else:
        if (n // 2) % 2 == 0:
            return 1
        else:
            return 0


def main():
    a, b = map(int, input().split())
    print(f(a - 1) ^ f(b))


if __name__ == "__main__":
    main()


Measured memory_bytes: 61832
//#define _GLIBCXX_DEBUG
//#include <atcoder/all>
#include <bits/stdc++.h>


using namespace std;
//using namespace atcoder;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

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 int MAX = 2010000;
long long 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;
}
// 前処理 COMinit();
// 計算例 cout << COM(100000, 50000) << endl;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N,K; cin>>N>>K;
  vector<ll> A(N); rep(i,N) cin>>A[i];
  sort(A.begin(),A.end());
  
  COMinit();
  ll ans=0;
  rep(i,N){
    ans+=A[i]*(COM(i,K-1)-COM(N-i-1,K-1))%MOD;
    ans%=MOD;
  }
  if(ans<0) ans+=MOD;
  
  cout<<ans<<'\n';
  
  return 0;
}


Measured memory_bytes: 51224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t
int main(){
    intf a = 100.0;
    intf n,i=0;
    cin >>n;
    for(i=0;;i++){
        if(a>=n) break;
         a *= 1.01;}
    cout << i<<endl;
}

Measured memory_bytes: 3624
import sys
import itertools
import math
input = lambda: sys.stdin.readline().rstrip()


def dist(D, x, y):

    ret = 0
    for i in range(D):
        ret += pow(x[i] - y[i], 2)

    return (ret ** 0.5).is_integer()


def solve():
    N, D = map(int, input().split())
    x = [[] for _ in range(N)]
    for i in range(N):
        x[i] = list(map(int, input().split()))

    ans = 0
    comb = list(itertools.combinations(range(N), 2))
    for c in comb:
        i1, i2 = c[0], c[1]
        if dist(D, x[i1], x[i2]):
            ans += 1

    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//UnionFind
//全て添字で扱うこと
struct union_find {
  vll parent;
  vll sizes;

  //初期化
  void init(ll n) {
    for (ll i = 0; i < n; i++) parent.push_back(i);
    for (ll i = 0; i < n; i++) sizes.push_back(1);
    return;
  }

  //頂点nの根
  ll root(ll n) {
    if (parent[n] == n) return n;
    return parent[n] = root(parent[n]);
  }

  //頂点nと間接的に繋がっている頂点の数(自身含む)
  ll size(ll n) {
    return sizes[root(n)];
  }

  //頂点a, bが間接的に繋がっているか判定
  bool is_united(ll a, ll b) {
    return (root(a) == root(b));
  }

  //頂点aを含むグラフに頂点bを含むグラフを結合
  void unite(ll a, ll b) {
    if (is_united(a, b)) return;
    sizes[root(a)] += size(b);
    parent[root(b)] = root(a);
    return;
  }
};

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

  union_find uf;
  uf.init(n);

  for (ll i = 0; i < m; i++) {
    ll a, b;
    cin >> a >> b;
    if (a == 1 || b == 1 || a == n || b == n) uf.unite(a - 1, b - 1);
  }

  if (uf.is_united(0, n - 1)) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int N, M;
  while(cin>>N>>M && N){
    vector<int> v1(N);
    vector<int> v2(M);
    REP(i, N) cin>>v1[i];
    REP(i, M) cin>>v2[i];
    int ans = 0;
    REP(s, M){
      if(M - s < ans) break;
      int g = s;
      REP(i, N){
        if(v1[i] == v2[g]) g++;
        if(g == M) break;
      }
      ans = max(ans, g - s);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 904
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;

void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	map<ll ,ll> mp;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	ll ans=0;
	for(auto it:mp)
	{
		if(it.second>=2)
		ans+=(it.second*(it.second-1))/2;
	}
	for(int i=0;i<n;i++)
	{
		if(mp[a[i]]<2)
			cout<<ans<<endl;
		else
		{
			ll dans=0;
			dans+=ans;
			dans-=(mp[a[i]]*(mp[a[i]]-1))/2;
			dans+=((mp[a[i]]-1)*(mp[a[i]]-2))/2;
			cout<<dans<<endl;
		}
	}
}
 
int main()
{
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

Measured memory_bytes: 11136
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

void dfs(const vector<vector<int>> &adj_lists, int cur, vector<int> &us) {
  us[cur] = 1;
  for (int nxt : adj_lists[cur]) {
    if (!us[nxt]) {
      dfs(adj_lists, nxt, us);
    }
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  int N, M;
  vector<int> ks;
  vector<vector<int>> lss;
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++) {
    int k, l;
    scanf("%d", &k);
    ks.push_back(k);
    lss.push_back(vector<int>());
    for (int j = 0; j < k; j++) {
      scanf("%d", &l);
      l--;  // NOTE : modified input
      lss[i].push_back(l);
    }
  }

  // create graph
  vector<vector<int>> adj_lists(M, vector<int>());
  for (int i = 0; i < N; i++) {
    const int l_0 = lss[i][0];
    for (int j = 1, j_end = lss[i].size(); j < j_end; j++) {
      const int l_j = lss[i][j];
      adj_lists[l_0].push_back(l_j);
      adj_lists[l_j].push_back(l_0);
    }
  }

  // solve
  int possible = 1;
  vector<int> us(M, 0);
  dfs(adj_lists, lss[0][0], us);
  for (vector<int> &ls : lss) {
    if (!us[ls[0]]) {
      possible = 0;
      break;
    }
  }
  if (possible) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }

  return 0;
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    string s;
    cin>>s;
    vector<int> n(4);
    REP(i,4) {
        n[i] = (int)(s[i] - '0');
    }
    REP(i,1<<4) {
        int t = i;
        string op;
        REP(j,4) {
            if (t%2 == 0) op.pb('+');
            else op.pb('-');
            t /= 2;
        }
        int res = n[0];
        REP(j,3) {
            if (op[j] == '+') res += n[j+1];
            else res -= n[j+1];
        }
        if (res == 7) {
            cout<<n[0]<<op[0]<<n[1]<<op[1];
            cout<<n[2]<<op[2]<<n[3]<<"=7"<<endl;
            return 0;
        }
    }
    return 0;
}

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

t = a[1]/2 - a[0]
c = 2 * a[0] - a[1] / 2

if (t % 1 == 0 and c % 1 == 0 and t >= 0 and c >= 0):
  print('Yes')
else:
  print('No')


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


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string S; cin >> S;
  int diff = 10000;
  for (int i = 0; i+2 < (int)S.size(); i++) {
    int x = (S.at(i) - '0') * 100
      + (S.at(i+1) - '0') * 10 + (S.at(i+2) - '0');
    diff = min(diff, abs(x - 753));
  }
  cout << diff << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    N,M = list(map(int,input().split()))
    a = [0]*N
    b=[0]*N
    for i in range(N):
        a[i],b[i] = list(map(int,input().split()))
    idxs = sorted(range(N),key=lambda x:a[x])
    rest=M
    ans=0
    for idx in idxs:
        ans += min(rest,b[idx])*a[idx]
        rest -= min(rest,b[idx])
        if rest==0:
            break

    print(ans)





if __name__=='__main__':
    main()

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

int main() {
 
    int a,b;
    cin>>a>>b;
 
    int ans=0;
    for(int i=1;i<=a;i++)
    {
        ans =ans+ b + i - 1;
    }
    if(b >= 0)
    {
        cout<<ans - b<<endl;
    }
    else if(b+a-1< 0)
    {
        cout<<ans-((a-1)+b)<<endl;
    }
    else{
        cout<<ans<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int x;
    cin >> x;
    cout << (x < 1200 ? "ABC" : "ARC") << endl;
}


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

bool check(std::string str) {
    std::string rev = str;
    std::reverse(rev.begin(), rev.end());
    if (str == rev) {
        return true;
    } else {
        return false;
    }
}

int main (int, char**) {
    std::string input;
    std::cin >> input;
    int size = input.size();

    std::string half1 = input.substr(0, (size - 1) / 2);
    std::string half2 = input.substr((size + 3) / 2 - 1);

    if (check(input) && check(half1) && check(half2)){
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256