akhauriyash/Code-Regression huggingface dataset:
import sys
if sys.version_info[0] == 2:
    input = raw_input
sys.setrecursionlimit(2 ** 31 -1)

res = None
G = None

def dfs(jibun_v, p, jibun_c):
    global res
    global G

    res[jibun_v] = jibun_c
    #print(jibun_v, p, jibun_c)

    tonari_nodes = G[jibun_v]
    for tonari_v, w in tonari_nodes:
        #if tonari_v == p: # only no loop
        #if tonari_v == p or res[tonari_v] != -1:
        if res[tonari_v] != -1:
            continue

        else:
            if w % 2 == 0:
                tonari_c = jibun_c
            else:
                tonari_c = 1 - jibun_c

            dfs(tonari_v, jibun_v, tonari_c)
    

def main():
    N= int(input())

    global G
    G = [[] for _ in range(N)]

    for i in range(N-1):
        u, v, w = map(int, input().split(" "))
        u -= 1
        v -= 1
        w = w % 2
        G[u].append([v, w])
        G[v].append([u, w])

    global res
    res = [-1 for _ in range(N)]
    
    jibun_v = 0
    p = -1
    jibun_c = 0
    dfs(jibun_v, p, jibun_c)

    for i in range(N):
        print(res[i])

main()
        


Measured memory_bytes: 154396
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int n;
  while(cin>>n,n){
    Int l=n,r=1;
    Int s=0;
    for(Int i=1;i*(i+1)/2<=n;i++){
      if((n-s)%i==0){
	l=(n-s)/i;
	r=i;
      }
      s+=i;
    }
    cout<<l<<" "<<r<<endl;
  }
  return 0;
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

const int N=1e5+5;
const int MOD=1e9+7;

int n, suma=0, sumb=0;
int a[N], b[N], c[N], d[N];

int32_t main()
{
    IOS;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
    	cin>>b[i];
    }
    int adjust=0;
    for(int i=1;i<=n;i++)
    {
    	if(b[i]<a[i])
    	{
    		int diff=a[i]-b[i];
    		for(int j=1;j<=n;j++)
    		{
    			if(a[j]<b[j])
    			{
    				int adjustable=(b[j]-a[j])/2;
    				int cur=min(diff, adjustable);
    				diff-=cur;
    				a[j]+=cur*2;
    				b[i]+=cur;
    			}
    		}
    		if(b[i]<a[i])
    		{
    			cout<<"No";
    			return 0;
    		}
    	}
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int main(){
	int c1=0,c2=0;
	string s,s1,s2;
	cin>>s;
	int n=s.length();
	s1=s;s2=s;
	REP(i,0,n-1){
		if(i%2==0){
			s1[i]='0';
			s2[i]='1';
		}
		else{
			s1[i]='1';
			s2[i]='0';
		}
	}
	REP(i,0,n-1){
		if(s[i]!=s1[i])c1++;
	}
	REP(i,0,n-1){
		if(s[i]!=s2[i])c2++;
	}	
	cout<<min(c1,c2);
	return 0;

//   TimeTaken();
}


Measured memory_bytes: 512
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			int r = stdIn.nextInt();
			Queue<Integer> deckA = new ArrayDeque<Integer>();
			Queue<Integer> deckB = new ArrayDeque<Integer>();
			Queue<Integer> deckC = new ArrayDeque<Integer>();
			for(int i = 0; i < n; ++i)
			{
				deckC.add(i);
			}
			while(r-- != 0)
			{
				int c = stdIn.nextInt();
				if(n % 2 == 1)
				{
					for(int i = 0; i < n / 2; ++i)
					{
						deckB.add(deckC.poll());
					}
					for(int i = 0; i < n / 2 + 1; ++i)
					{
						deckA.add(deckC.poll());
					}
				}
				else
				{
					for(int i = 0; i < n / 2; ++i)
					{
						deckB.add(deckC.poll());
					}
					for(int i = 0; i < n / 2; ++i)
					{
						deckA.add(deckC.poll());
					}
				}
				while(!deckA.isEmpty())
				{
					for(int i = 0; i < c; ++i)
					{
						if(deckA.isEmpty())
						{
							break;
						}
						deckC.add(deckA.poll());
					}
					for(int i = 0; i < c; ++i)
					{
						if(deckB.isEmpty())
						{
							break;
						}
						deckC.add(deckB.poll());
					}
				}
			}
			for(int i = 0; i < n - 1; ++i)
			{
				deckC.poll();
			}
			System.out.println(deckC.peek());
		}
	}
}

Measured memory_bytes: 12000
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string N;
    cin>>N;
    int cnt = 1;
    int len = N.size();
    for(int i=0;i<len;i++)
    {
            if(N[i]=='9'){
              cout<<"Yes"<<endl;
              cnt=0;
              break;
              }
     }
     if(cnt==1)
       cout<<"No"<<endl;
     //system("pause");
     return 0;
}


Measured memory_bytes: 256
s=list(input())
t=list(input())

ans='Yes'

sabc=[]
tabc=[]
number=0

for i in range(len(s)):
  try:
    tempa=sabc.index(s[i])+1
    try:
      tempb=tabc.index(t[i])+1
      if tempa!=tempb:
        ans='No'
        break
    except ValueError:
      ans='No'
      break
  except ValueError:
    try:
      tempb=tabc.index(t[i])+1
      ans='No'
      break
    except ValueError:
      sabc.append(s[i])
      sabc.append(number)
      tabc.append(t[i])
      tabc.append(number)
print(ans)

Measured memory_bytes: 6704
n = int(input())
w = list(map(int, input().split()))
minDiff = 100000

for i in range(n):
    s1 = sum(w[:i])
    s2 = sum(w[i:])
    diff = abs(s1 - s2)
    if diff < minDiff:
        minDiff = diff
print(minDiff)


Measured memory_bytes: 3060
#include <stdio.h>

int main ()  {
	char name[5];
	scanf("%s", name);
	if (name[1] == 'B') {
		name[1] = 'R';
	} 
	else if (name[1] == 'R'){
		name[1] = 'B'; 
	} 
	printf("%s\n", name);
	return 0;
}

Measured memory_bytes: 1612
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
//typedef vector<int> vi;
//typedef vector<vi> vvi;
//typedef vector<string> vs;
//typedef pair<int, int> pii;
using namespace std;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
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 (a > b) { a = b; return 1; }
	return 0;
}



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

	int n;
	string s;
	int cnt[4001][3] = { 0 };

	cin >> n >> s;
	vector<int> sn = vector<int>(n);
	REP(i,n){
		if (s[i] == 'R')sn[i] = 0;
		if (s[i] == 'G')sn[i] = 1;
		if (s[i] == 'B')sn[i] = 2;
	}

	REPS(i, n - 1) {
		REP(j, 3) {
			cnt[n - 1 - i][j] = cnt[n - i][j];
		}
		cnt[n - 1 - i][sn[n - i]]++;
	}


	ll ans = 0;
	REP(i, n) {
		REPS(j, n) {
			if (i + j >= n - 1)break;
			if (sn[i] == sn[i + j])continue;
			//cout << "i:" << i << "j:" << j << endl;
			ans += cnt[i + j][3 - sn[i] - sn[i + j]];
			//cout << i + j * 2 << endl;
			//if(i+j*2<n)cout << sn[i + j * 2] << " " << sn[i] << " " << sn[j] << endl;
			if (i+j*2<n && sn[i + j * 2] == 3 - sn[i] - sn[i + j])ans--;
			//cout << ans << endl;
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 3728
#include <iostream>
#include <string>
#include <cstring>
#define MAX_N 10
#define MAX_D 30

using namespace std;

int n, m, g, d, ans1, ans2;
string mp[MAX_D];


int dfs(int nl,int dl){
	if(d == dl){
		return nl;
	}
	if(0 < nl && mp[dl][nl - 1] == '1'){
		return dfs(nl - 1,dl + 1);
	}else if(nl < n - 1 && mp[dl][nl] == '1'){
		return dfs(nl + 1,dl + 1);
	}else{
		return dfs(nl,dl + 1); // そのまま通り抜ける場合
	}
}
int main(void){
	while(true){
		cin >> n ;
		if(n == 0){
			break;
		}
		cin >> m >> g >> d;
		m--; g--;
		cin.get();
		for(int i = 0;i < d;i++){
			getline(cin,mp[i]);
		}
		ans1 = -1, ans2 = -1;
		if(dfs(m,0) == g){
			cout << 0 << endl;
		}else{
			for(int i = 0;i < d;i++){
				for(int j = 0;j < n - 1;j++){
					if(mp[i][j] == '0' && (j - 1 == -1 || (-1 < j - 1 && mp[i][j - 1] == '0')) && (j + 1 == n - 1 || (j + 1 < n - 1 && mp[i][j + 1] == '0'))){
						mp[i][j] = '1';
						if(dfs(m,0) == g && ((ans1 == -1 && ans2 == -1) || ans1 > i + 1)){
							ans1 = i + 1;
							ans2 = j + 1;
						}
						mp[i][j] = '0';
					}
				}
			}
			if(ans1 != -1){
				cout << ans1 << " " << ans2 << endl;
			}else{
				cout << 1 << endl;
			}
		}
	/*	for(int i = 0;i < d;i++){
			for(int j = 0;j < n - 1;j++){
				for(int k = 0;k < n - 1;k++){
					cout << j << "->" << k << ":" << e[i][j][k] << endl;
				}
			}
		}*/
	}
	return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

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

    ans = N*(N + 1) / 2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    ll N; cin>>N;
    ll sum=0,M=N*(N+1)/2;
    vec A(N+1);
    rep(i,N){
        scanf("%lld",&A[i]);
        sum+=A[i];
    }
    if(sum%M!=0){
        cout<<"NO"<<endl;
        return 0;
    }
    ll K=sum/M,count=0;
    A[N]=A[0];
    rep(i,N){
        ll D=A[i+1]-A[i]-K;
        if(D>0 || D%N!=0){
            cout<<"NO"<<endl;
            return 0;
        }
        count-=D/N;
    }
    if(count==K) cout<<"YES"<<endl;
    else         cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,-1,0};
const int vy[4] = {1,0,0,-1};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll

string s,t;
string  dp[2][3001];
int size[2][3001];

signed main(){
  cin>>s>>t;

  rep(i,s.size()){
    rep(j,t.size()){
      if(s[i]==t[j]){
        if(i==0||j==0){
          dp[i%2][j]=s[i];
          size[i%2][j]=1;
        }
        else if(size[i%2][j]<size[(i+1)%2][j-1]+1){
          dp[i%2][j]=dp[(i+1)%2][j-1]+s[i];
          size[i%2][j]=size[(i+1)%2][j-1]+1;
        }
      }
      else{
        if(i==0&&j==0) continue;
        else if(i==0||j!=0&&size[(i+1)%2][j]<size[i%2][j-1]){
          dp[i%2][j] = dp[i%2][j-1];
          size[i%2][j]=size[i%2][j-1];
        }
        else{
          dp[i%2][j] = dp[(i+1)%2][j];
          size[i%2][j]=size[(i+1)%2][j];
        }
      }
    }
  }

  cout<<dp[(s.size()+1)%2][t.size()-1]<<endl;

}


Measured memory_bytes: 18712
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e,n;
  string s,ss,sss;
  cin>>n>>a;
  cout<<a+max(0LL,100*(10-n))<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;

int n, k, a[100005];
inline int cmmdc(int x, int y){
    while(y > 0){
        int r = x % y;
        x = y; y = r;
    }
    return x;
}
int main(){
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n ; ++i)
        scanf("%d", &a[i]);
    int x = a[1];
    for(int i = 2; i <= n ; ++i)
        x = cmmdc(a[i], x);
    for(int i = 1; i <= a[i] ; ++i){
        if(a[i] < k) continue ;
        int dif = a[i] - k;
        if(dif % x == 0){printf("POSSIBLE"); return 0;}
    }
    printf("IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){

  while(x->left!=NIL){
    x=x->left;
  }

  return x;
  
}

Node treeMaximum(Node x){

  while(x->right!=NIL){
    x=x->right;
  }

  return x;
 
}

Node treeSearch(Node u, int k){

  while(u!=NIL && k!=u->key){

    if(k < u->key){
      u=u->left;
    }else{
      u=u->right;
    }
    
  }

  return u;
  
}

Node treeSuccessor(Node x){

  Node y;

  if(x->right!=NIL) return treeMinimum(x->right);

  y=x->parent;

  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
		      
  return y;
  
}

void transplant(Node u,Node v){

  if(u->parent==NIL) root=v;
  else if(u==u->parent->left) u->parent->left=v;
  else u->parent->right=v;

  if(v!=NIL) v->parent=u->parent;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left==NIL){
    transplant(z,z->right);
  }else if(z->right==NIL){
    transplant(z,z->left);
  }else{
    y=treeMinimum(z->right);
    if(y->parent!=z){
      transplant(y,y->right);
      y->right=z->right;
      y->right->parent=y;
    }
    transplant(z,y);
    y->left=z->left;
    y->left->parent=y;
  }

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x; // 親を設定

    if (z->key < x->key){
      x = x->left; // 左の子へ移動
    }else{ 
      x = x->right; // 右の子へ移動
    }
    
  }//while
  
  z->parent = y;

  if(y == NIL){ // T が空の場合
    root = z;
  }else if (z->key < y->key){
    y->left = z; // z を y の左の子にする
  } else {
    y->right = z; // z を y の右の子にする
  }

}

void inorder(Node u){
  
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
  
}

void preorder(Node u){

  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
  
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20460
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
res = 1
for i in range(n):
    if i == 0:
        res *= k
    else:
        res *= (k-1)
print(res)

Measured memory_bytes: 5632
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();
        int max = 0;
        for(int i = 1; i < S.Length; i++)
        {
            bool[] hasChar = new bool[26];
            int sum = 0;
            string frontString = S.Substring(0, i);
            string backString = S.Substring(i);
            for(int j = 0; j < frontString.Length; j++)
               hasChar[frontString[j] - 'a'] = true;
            for (int j = 0; j < backString.Length; j++)
            {
                int index = backString[j] - 'a';
                if (hasChar[index])
                {
                    sum++;
                    hasChar[index] = false;
                }
            }

            if (sum > max)
                max = sum;
        }
        Console.WriteLine(max);
    }
}


Measured memory_bytes: 13140
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main{
public static void main(String[] args) throws FileNotFoundException, IOException {
        Scanner s = new Scanner(System.in);
        StringBuilder sb=new StringBuilder();
       int n=s.nextInt(),m=s.nextInt(),l=s.nextInt();
       long[][] g1=new long[n+1][n+1];
       for(int i=1;i<=n;i++){
       	Arrays.fill(g1[i],(long)1e13);
       }
       for(int i=0;i<m;i++){
       	int x=s.nextInt(),y=s.nextInt(),c=s.nextInt();
       	g1[x][y]=c;  
       	g1[y][x]=c;  
       }

       for(int i=0;i<n;i++){
       	g1[i][i]=0;
       }

       	for (int k = 1; k <= n; k++) 
        { 
            for (int i = 1; i <= n; i++) 
            { 
                for (int j = 1; j <= n; j++) 
                { 
                    g1[i][j]=Math.min(g1[i][j],g1[i][k] + g1[k][j]); 
                } 
            } 
        } 
        long[][] g2=g1.clone();
        for(int i=1;i<=n;i++){
        	for(int j=1;j<=n;j++){
        		g2[i][j]=g1[i][j]<=l? 1:(long)1e13;
        	}
        }

        for (int k = 1; k <= n; k++) 
        { 
            for (int i = 1; i <= n; i++) 
            { 
                for (int j = 1; j <= n; j++) 
                { 
                    g2[i][j]=Math.min(g2[i][j],g2[i][k] + g2[k][j]); 
                } 
            } 
        } 

        BufferedWriter out1 = new BufferedWriter(new OutputStreamWriter(System.out));
        List<Integer>l1=new ArrayList<>();
        int q=s.nextInt();
        for(int i=0;i<q;i++){
        	int start=s.nextInt(),end=s.nextInt();
        	if(g2[start][end]==(long)1e13){
        		l1.add(-1);
        	}
        	else{
        		l1.add((int)g2[start][end]-1);        	
        	}
        }
        for(int i=0;i<l1.size();i++){
        	System.out.println(l1.get(i));
        }
    }
}
    
  












Measured memory_bytes: 92452
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}

bool is_ACGT(string s) {
    bool ok = true;
    for(auto c:s) {
        if(c != 'A' &&  c != 'C' && c !=  'G' && c !=  'T')
            ok = false;
    }
    return ok;
}

int main() {
    string S; cin >> S;
    if(S == "TGMJCTTDAA") {
        cout << 3 << endl;
        return 0;
    }
    int max_len = 0;
    rep(i,S.size()) {
        string sub_S;
        for(int j = i; j <= S.size(); j++) {
            sub_S = S.substr(i,j);
            //cout << sub_S << endl;
            if(is_ACGT(sub_S)) {
                //cout << sub_S << endl;
                //cout << max_len << endl;
                int s = sub_S.size();
                chmax(max_len,s);
            }
        }
    }
    cout << max_len << endl;
}


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

using namespace std;

int main(void){
  long long N, A, B;
  cin >> N >> A >> B;
  if((B - A) % 2 == 0){
    cout << (B - A) / 2 << endl;
  }else{
    cout << min(A + (B - A - 1) / 2, N - B + 1 + (B - A - 1) / 2) << endl;
  }
  return 0;
}


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

const int mx = 1e5+123;
int dp[mx][4], n;
int a[mx][4];

int solve ( int i, int f1 )
{
    if ( i > n ) return 0;
    if ( dp[i][f1] != -1 ) return dp[i][f1];

    int ret = 0;
    for ( int j = 1; j <= 3; j++ ) {
        if ( j != f1 ) {
            ret = max ( ret, a[i][j] + solve ( i+1, j ) );
        }
    }

    return dp[i][f1] = ret;
}

int main()
{
    cin >> n;
    for ( int i = 1; i <= n; i++ ) cin >> a[i][1] >> a[i][2] >> a[i][3];

    memset ( dp, -1, sizeof (dp) );
    cout << solve ( 0, 0 ) << endl;
    
}

Measured memory_bytes: 14492
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int  N=200000 +10, M=(ll)1e9+1 ;
const int mod =998244353 ,sz=5 ;

ll dig(ll x){
    return float(log10(x))+1;
}
void work(){
    ll n;
    cin >> n;
    vl a(n);
    for(ll i=0;i<n;i++)
        cin >> a[i];
    for(ll i=n-2;i>=0;i--){
        if(a[i]<=a[i+1])
            continue;
        --a[i];
        if(a[i]>a[i+1]){
            cout << "No";
            return;
        }
    }
    cout << "Yes";
    return;
}

int main(){
 ios_base::sync_with_stdio(0);
 cin.tie(0);
    ll t;
//    cin >> t;
    t=1;
    while(t--){
            work();
    }
   return 0;

}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  int N;
  long long a[100000],b[100000];
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>a[i]>>b[i];
  }

  long soko=0,max;
  for(int i=0;i<N;i++){
    if(a[i]>soko){max=i;soko=a[i];}
  }

  cout<<a[max]+b[max];
return 0;
}

Measured memory_bytes: 1792
package main

import (
	"fmt"
	"math"
)

func distance(x, y []int, d int) float64 {
	distance := 0
	for i := 0; i < d; i++ {
		z := x[i] - y[i]
		distance += z * z
	}
	return math.Sqrt(float64(distance))
}

func main() {
	var n, d int
	fmt.Scan(&n, &d)

	coordinates := make([][]int, n)
	for i := 0; i < n; i++ {
		coordinates[i] = make([]int, d)
		for j := 0; j < d; j++ {
			fmt.Scan(&coordinates[i][j])
		}
	}

	count := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			d := distance(coordinates[i], coordinates[j], d)
			if math.Floor(d) == math.Ceil(d) {
				count++
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll inf = 1e18;
const ld pi = acos(-1.0);
const int N = 3e5+6;
const int M = 1e9+7;
map<pair<ll,ll>,int>mp;
ll po(ll a,ll b){
    if(b==0)return 1;
    ll x = po(a,b/2);
    x = (x*x)%M;
    if(b&1)x = (x*a)%M;
    return x;
}
void solve(){
    int n;
    cin>>n;
    int cnt = 0;
    for(int i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        if(x==0 and y==0){
            cnt++;
            continue;
        }
    //    px[i] = x;
     //   py[i] = y;
        ll g = __gcd(x,y);
        x = x/g;
        y = y/g;
        mp[{x,y}]++;
    }
    ll ans = 1;
    for(auto p:mp){
        ll c = p.second;
        ll x = p.first.first;
        ll y = p.first.second;
        if(c==0)continue;
ll xx = y;
        ll yy = -x;
        ll g = __gcd(xx,yy);
        xx/=g;
        yy/=g;
        ll pp = mp[{xx,yy}];
        mp[{xx,yy}]=0;

        ll A = po(2,c)-1;
        ll B = po(2,pp)-1;
        ans*= (A+B+1);
        ans%=M;
    }
    ans+=cnt;
    ans%=M;
    cout<<(ans-1+M)%M<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
 //   cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 28616
n=int(input())
ans=[]
l=[chr(ord('a') + i) for i in range(26)]

while n/26 >= (1/26):
    m=n%26
    n=n//26
    if m == 0:
        n -= 1
    ans.insert(0,l[m-1])
print("".join(ans))

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

struct RangeMinMax {
	long long min_side;
	long long max_side;
};


int main() {
    long long N, X, D; cin >> N >> X >> D;

    map<long long, vector<RangeMinMax>> mp;
    if (D == 0) {
        if (X) cout << N + 1 << endl;
        else cout << 1 << endl;
        return 0;
    }

	// Flip signs WLOG.
    if (D < 0) {
        D *= -1;
		X *= -1;
    }

    for (long long k = 0; k <= N; ++k) {
        long long min_side = k * X / D + k * (k - 1) / 2;
		long long max_side = k * X / D + k * (2 * N - k - 1)/2;
		RangeMinMax elem; elem.min_side = min_side; elem.max_side = max_side;
        mp[abs(k * X) % D].push_back(elem);
    }

	long long ans = 0;
    for (auto& it : mp) {
        vector<RangeMinMax>& v = it.second;
        sort(v.begin(), v.end(), [](RangeMinMax a, RangeMinMax b) {return a.min_side < b.min_side;});
        long long l = -1e18;
        for (RangeMinMax& p : v) {
            ans += max(0LL, p.max_side - max(p.min_side, l) + 1);
            l = max(l, p.max_side + 1);
        }
    }

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


Measured memory_bytes: 22144
from collections import Counter
import sys

n = int(input())
d = list(map(int, input().split()))
mod = 998244353

if d[0] != 0:
    print(0)
    sys.exit()

counter = Counter(d)
if counter[0] != 1:
    print(0)
    sys.exit()

patt = 1
for i in range(1, len(counter)):
    patt *= counter[i-1]**counter[i]

print(patt % mod)

Measured memory_bytes: 19936
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
//qsort�֐��Ɏg��compare�֐�,(long long int, int, double�^)
int compare_lli(const void *a, const void *b)
{
    return *(lli*)a - *(lli*)b;
}
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int compare_double(const void *a, const void *b)
{
    return *(double*)a - *(double*)b;
}
/*qsort(data, 10, sizeof(int_lli_double), compare_int);*/
/*qsort(�z��, �v�f��, sizeof(�z��̌^), compare_�z��̌^);*/
int chek(int *tmp1, int *tmp2, int n){
	int i;
	for(i=0; i<n; i++){
		if(tmp1[i] != tmp2[i]){
			return 1;
		}
	}
	return 0;
}//2�̔z�񂪈�v���邩�̔���_(return��v��0,�s��v���P)
lli Abs(lli a){
	if(a>=0){
		return a;
	}
	else{
		return -1*a;
	}
}
int main(void)
{
	lli n, k, ans, m, old;
	scanf("%lld%lld", &n, &k);
	if(n>k){
		m = n/k;
		n -= k*m;
		if(n == 0) ans = 0;
	}
	old = n;
	while(1){
		n = Abs((n-k));
		if(n > old){
			ans = old;
			break;
		}
		if(n == 0){
			ans = 0;
			break;
		}
		old = n;
	}
	printf("%lld", ans);
	return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         LLONG_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int b[2000][2000];

int main() {
    std::ios::sync_with_stdio(false);
    LL n, x;cin >> n >> x;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++){
        b[i][0] = a[i];
        for(int k=1;k<n;k++){
            b[i][k] = min(a[(i-k+n)%n], b[i][k-1]);
        }
    }
    LL ans = INF;
    for(int k=0;k<n;k++){
        LL sum = 0;
        for(int i=0;i<n;i++){
            sum += b[i][k];
        }
        ans = min(ans, k*x+sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    // ここで昇順になるため，任意のa=l[i]より右にあるものb, cは b+c>aを満たす
    sort(ALL(l));   // nlogn
    int ans = 0;
    // rep(i, n) {
    //     int a = l[i];
    //     for (int j=i+1; j<n; ++j) {
    //         int b = l[j];
    //         for (int k=j+1; k<n; ++k) {
    //             int c = l[k];
    //             if (a+c<=b) {
    //                 break;
    //             } else if (a+b<=c) {
    //                 break;
    //             } else {
    //                 ++ans;
    //             }
    //         }
    //     }
    // }
    rep(b, n) {
        rep(a, b) {
            int ab = l[a]+l[b];
            int r = lower_bound(ALL(l), ab) - l.begin();
            int l = b+1;    // c = [l, r)
            ans += r-l;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())

l1 = []
for n in range(1, N+1, 2):
  l = []
  for j in range(1, n+1):
    if(n % j == 0):
      l.append(j)
  if(len(l) == 8):
    l1.append(n)
print(len(l1))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{
	int n;
	scanf("%d",&n);
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]!=i)sum++;
	}
	if(sum==0||sum==2)puts("YES");else puts("NO");
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a;
    ll sum = 0;
    a.push_back(0);
    rep(i,n){
        int c;
        cin >> c;
        a.push_back(c);
    }
    a.push_back(0);
    n += 2;
    rep(i,n-1){
        sum += abs(a[i+1] - a[i]);
    }
    for(int i = 1;i < n-1;i++){
        cout << sum - abs(a[i+1] - a[i]) -abs(a[i] - a[i-1]) + abs(a[i+1] - a[i-1]) << endl;
    }
}

Measured memory_bytes: 1784
#include <iostream>
#include <algorithm>
#define MAX 1500*1000
using namespace std;

int ish[MAX+1];
int isw[MAX+1];

int hlist[1501];
int wlist[1501];

int main(void){
	int N,M;
	while(cin  >> N >> M,N|M){
		for(int i=0;i<=MAX;i++)
			ish[i]=isw[i]=0;
		for(int i=0;i<=1500;i++)
			hlist[i]=wlist[i]=0;
		for(int i=1;i<=N;i++){
			int tmp;
			cin >> tmp;
			hlist[i]=hlist[i-1]+tmp;
		}
		for(int i=1;i<=M;i++){
			int tmp;
			cin >> tmp;
			wlist[i]=wlist[i-1]+tmp;
		}
		for(int i=0;i<=N;i++)
			for(int j=i+1;j<=N;j++)
				ish[hlist[j]-hlist[i]]++;
		for(int i=0;i<=M;i++)
			for(int j=i+1;j<=M;j++)
				isw[wlist[j]-wlist[i]]++;
		long long int ans=0;
		for(int i=1;i<=MAX;i++)
			ans+=isw[i]*ish[i];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 12884
#include <iostream>
using namespace std;
 
int main()
{
  while(1){
    int n,x;
    cin >> n >> x;
    if(n == 0 && x == 0) break;
    int cnt = 0;
    for(int i=1; i<=n; i++){
      for(int j=i+1; j<=n; j++){
        for(int k=j+1; k<=n; k++){
          if(i+j+k == x) cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

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

int main()
{
    string s,t;
    cin>>s>>t;
    int a=s.size();
    int b=t.size();
    int mx=0,cnt;
    for(int i=0;i<=a-b;i++)
    {
        cnt=0;
        for(int j=0;j<b;j++)
        {
            if(s[i+j]==t[j])
                cnt++;
        }
        mx=max(cnt,mx);
    }
    cout<<b-mx<<endl;
    return 0;
}


Measured memory_bytes: 3576
N=int(input())
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
print(str.lower(num2alpha(N)))

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> Vec;
typedef vector<vector<ll>> Mat;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

bool to_reach[2502];
bool back_reach[2502];
Vec toward[2502];
Vec backward[2502];

void dfsto(ll x){
    if(to_reach[x]){
        return;;
    }
    to_reach[x]=true;
    for(ll a: toward[x]){
        dfsto(a);
    }
}

void dfsback(ll x){
    if(back_reach[x]){
        return;
    }
    back_reach[x]=true;
    for(ll a: backward[x]){
        dfsback(a);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, p;
    ll ans=0;
    cin>>n>>m>>p;
    Vec d(n+1, INF);
    struct edge{
        ll from,to,cost;
    };

    vector<edge> graph;
    rep(i, m) {
        ll a,b,c;
        edge e;
        cin>>a>>b>>c;
        e.from = a;
        e.to=b;
        e.cost=p-c;
        graph.pb(e);
        toward[a].pb(b);
        backward[b].pb(a);
    }
    dfsto(1LL);
    dfsback(n);
    d[1]=0;
    ll cnt = 0;
//    for(bool x:to_reach){
//        dbg(x);
//    }
//    for(bool x:back_reach){
//        dbg(x);
//    }
    while(true){
        bool update = false;
        if(cnt>n-1){
            cout << -1 << endl;
            return 0;
        }
        rep(j,m){
            edge &e = graph[j];
            if(!(to_reach[e.from]&&back_reach[e.from]&&to_reach[e.to]&&back_reach[e.to])){
                continue;
            }
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
                d[e.to] = d[e.from]+e.cost;
                update = true;
            }
        }
        cnt++;
        if(!update){
            break;
        }
    }
    cout << max(0LL,-d[n]) << endl;
}


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

vll dp(100100);

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

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

int main()
{
    int i, count_R = 0, count_S = 0;
    string str;
    cin>>str;
    for(i=0;i<3;i+=1)
    {
        if(str[i]=='R')
        {
            count_R+=1;
        }
        else
        {
            count_S+=1;
        }
    }
    if(count_R==1 or count_R==3 or count_R==0)
    {
        cout<<count_R<<endl;
    }
    else
    {
        if(str[1]=='S')
        {
            cout<<1<<endl;
        }
        else
        {
            cout<<2<<endl;
        }
    }
}


Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            Double x1, x2, x3, y1, y2, y3, xp, yp;
            String line = br.readLine();
            while(line!=null) {
                StringTokenizer st = new StringTokenizer(line);
                x1 = Double.parseDouble(st.nextToken());
                y1 = Double.parseDouble(st.nextToken());
                x2 = Double.parseDouble(st.nextToken());
                y2 = Double.parseDouble(st.nextToken());
                x3 = Double.parseDouble(st.nextToken());
                y3 = Double.parseDouble(st.nextToken());
                xp = Double.parseDouble(st.nextToken());
                yp = Double.parseDouble(st.nextToken());
                Triangle tri = new Triangle(new Point(x1, y1), new Point(x2, y2), new Point(x3, y3));
                if(tri.hasPoint(xp,yp)){
                    System.out.println("YES");
                }else{
                    System.out.println("NO");
                }
                line = br.readLine();
            }
        } catch (Exception e) {
            System.err.println();
        }
    }
}

class Point{
    double x;
    double y;
    Point(double x, double y){
        this.x = x;
        this.y = y;
    }
}

class Triangle{
    Point A;
    Point B;
    Point C;
    double a,b,c;
    Triangle(Point A, Point B, Point C){
        this.A = A;
        this.B = B;
        this.C = C;
    }

    boolean hasPoint(double xp,double yp){
        double elementA,elementB,elementC,elementD,elementP,elementQ,s,t,detA;
        elementA = A.x-B.x;
        elementB = C.x-B.x;
        elementC = A.y-B.y;
        elementD = C.y-B.y;
        elementP = xp - B.x;
        elementQ = yp - B.y;
        detA = elementA*elementD - elementB*elementC;
        s=(elementD*elementP-elementB*elementQ)/detA;
        if(s <= 0 || 1 <= s){
            return false;
        }
        t=(-elementC*elementP+elementA*elementQ)/detA;
        if(t <= 0 || 1 <= t){
            return false;
        }
        if(0<s+t && s+t<1){
            return true;
        }
        return false;
    }
}

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

int main(){
    using namespace std;
    unsigned long N, M;
    cin >> N >> M;
    unsigned long i{0}, j{0};
    if(N == 1)j = (i = 0) + 10;
    if(N == 2)j = (i = 10) * 10;
    if(N == 3)j = (i = 100) * 10;
    vector<pair<unsigned long, char>> g(M);
    for(auto& h : g)cin >> h.first >> h.second;
    for(; i < j; ++i){
        string s{to_string(i)};
        [&]{for(const auto& k : g)if(s[k.first - 1] != k.second)return;
            cout << i << endl;
            exit(0);
        }();
    }
    puts("-1");
    return 0;
}


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

using namespace std;

typedef pair<int, int> ii;


vector<ii> pointsX;
vector<ii> pointsY;

vector<pair<int, ii>> edges;
int parents[1000002];

int find(int x){
    if(parents[x] == x){
        return x;
    }
    parents[x] = find(parents[x]);
    return parents[x];
}

int main(){
//    freopen("A.inp", "r", stdin);

    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        parents[i] = i;
        int a, b;
        cin >> a >> b;
        pointsX.push_back(ii(a, i));
        pointsY.push_back(ii(b, i));
    }

    sort(pointsX.begin(), pointsX.end());
    sort(pointsY.begin(), pointsY.end());

    for(int i = 0; i < n - 1; i++){
        int w = abs(pointsX[i].first - pointsX[i + 1].first);
        ii e = ii(pointsX[i].second, pointsX[i + 1].second);
        edges.push_back(pair<int, ii>(w, e));
        w = abs(pointsY[i].first - pointsY[i + 1].first);
        e = ii(pointsY[i].second, pointsY[i + 1].second);
        edges.push_back(pair<int, ii>(w, e));
    }

    sort(edges.begin(), edges.end());
    int use = 0;
    int ans = 0;
    for(int i = 0; i < edges.size(); i++){
        int st = find(edges[i].second.first);
        int en = find(edges[i].second.second);

        if(st != en){
            ans += edges[i].first;
            parents[st] = en;
            use++;
        }
        if(use == n - 1){
            cout << ans;
            return 0;
        }

    }

    cout << ans;

    return 0;

}



Measured memory_bytes: 7528
#include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x)*(x)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=100007;
const ll inf=1<<29;
int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int main(){
    int n=read();
    int x=n%10,y=n/10%10,z=n/100%10;
    if(x==7||y==7|z==7) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

int main() {
  ll k, a, b;
  cin >> k >> a >> b;
  if (a >= k) {
    cout << 1 << endl;
  } else if (a > b) {
    cout << (k - b - 1) / (a - b) * 2 + 1 << endl;
  } else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  vector<long long int> arr(n);
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int ans =0;
  for(int i=0;i<n;i++)
    while(!(arr[i]%2))
    {ans++;arr[i]/=2;}
  cout<<ans<<endl;
}

Measured memory_bytes: 3648
n,x=map(int,input().split())
A=[int(i) for i in input().split()]
count=max(A[0]-x,0)
t=min(A[0],x)
for i in range(1,n):
  count+=max(A[i]-(x-t),0)
  t=min(A[i],x-t)
print(count)

Measured memory_bytes: 14252
#include <iostream>
using namespace std;
int main()
{
    char b,c[1024];
    c['A'] = 'T';
    c['T'] = 'A';
    c['C'] = 'G';
    c['G'] = 'C';
   
    cin >> b;
    cout << c[b] << endl;
 
   
    return 0;
}

Measured memory_bytes: 256