akhauriyash/Code-Regression huggingface dataset:
///******* In the name of Allah *******///

#include <bits/stdc++.h>
using namespace std;

//long int ar[90013],br[100013];
//long int gcd(long int a, long int b)
//{
//    if(b==0)
//        return a;
//    return gcd(b,a%b);
//}
//long int sieve(long long int a)
//{
//    //long long int i,j,k = 0;
//    memset(ar,0,sizeof(ar));
//    ar[1] = 1;
//    for(i=2; i<=90013; i++)
//    {
//        if(ar[i]==0)
//        {
//            k++;
//            br[k] = i;
//            for(j=i+i; j<=90013; j+=i)
//            {
//                ar[j] = 1;
//            }
//        }
//    }
//    return br[a];
//}

void Ok()
{
    long int a[77],b,c,d,h,t,i,j,k,l,m,n;
    long int ans_1,ans_2,ans_3,ans_4,cnt = 0,Max,Min,flag,temp,sum_1,sum_2;
    double aa,bb,cc,dd,ee,ff,gg;
    char aaa[10013],bbb,ccc,ddd;
    string spc,in;

    cin>>in;
    if(in=="ABC")
        cout<<"ARC"<<endl;
    else
        cout<<"ABC"<<endl;

    return;
}

int main()
{
    Ok();

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  string S; cin >> S;
  int N = (int)S.size();
  vector<vector<ll>> dp(N+1, vector<ll>(13, 0));
  vector<ll> beki(N+1, 0);
  beki[1] = 1;
  for(int i=2; i<N+1; i++){
    beki[i] = (beki[i-1]*10) % 13;
  }

  dp[0][0] = 1;
  int nr;
  for(int k=1; k<=N; k++){
    for(int r=0; r<13; r++){
      if (S[N-k] == '?'){
        for(int i=0; i<10; i++){
          nr = (r + i*beki[k]) % 13;
          dp[k][nr] = (dp[k][nr] + dp[k-1][r]) % MOD;
        }
      } else {
          int i = (int)S[N-k] - (int)'0';
          nr = (r + i*beki[k]) % 13;
          dp[k][nr] = (dp[k][nr] + dp[k-1][r]) % MOD;
      }
    }
  }

  cout << dp[N][5] << endl;
  
  return 0;
}

Measured memory_bytes: 14464
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
  int N; cin >> N;
  vector<int> a(N), b(N), c(N);
  for (int i = 0; i < N; i++) cin >> a[i] >> b[i] >> c[i];

  vector< vector<int> > DP(100100, vector<int>(3));
  DP[0][0] = a[0];
  DP[0][1] = b[0];
  DP[0][2] = c[0];

  for (int i = 1; i < N; i++) {
    DP[i][0] = max(DP[i - 1][1] + a[i], DP[i - 1][2] + a[i]);
    DP[i][1] = max(DP[i - 1][0] + b[i], DP[i - 1][2] + b[i]);
    DP[i][2] = max(DP[i - 1][0] + c[i], DP[i - 1][1] + c[i]);
  }
  cout << max(DP[N - 1][0], max(DP[N - 1][1], DP[N - 1][2])) << endl;
}


Measured memory_bytes: 6912
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int pop();
void push();
int top, A[1000];

int main(){
  int a,b;
  char c[100];
  
  top=0;
  while(scanf("%s",c)!=-1){
    if(c[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(c[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(c[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else
      push(atoi(c));
  }

  printf("%d\n",pop());
 
  return 0;
}

int pop(){
  top--;
  return A[top+1];
}

void push(int x){
  A[++top]=x;
}

Measured memory_bytes: 548
#include<bits/stdc++.h>
#define F first
#define S second
using ll = long long;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using namespace std;
using vl = vector<ll>;
using pll =  pair<ll,ll>;



void  solve(){
    float n,h,w;
    cin>>h>>w>>n;
    cout<<ceil(n/max(h,w));
    
}
        
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //int n; cin>>n; for(int i=0;i<n;i++)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 int main(void)
{
 int a[3][10][4] = {0};
 int i, j, k;
 int n, p;
 int b, f, r, v; /* b棟f階r番目の部屋にv人 [階][部屋][棟] */
 scanf("%d", &n);
 for(i=0;
 i<n;
 i++)
{
 scanf("%d%d%d%d", &b, &f, &r, &v);
 a[f-1][r-1][b-1] += v;
 }
 for(k=0;
 k<4;
 k++)
{
 for(i=0;
 i<3;
 i++)
{
 for(j=0;
 j<10;
 j++)
{
 if(a[i][j][k] == 0)
{
 printf(" 0");
 }
else
{
 printf(" %d", a[i][j][k]);
 }
 }
 printf("\n");
 }
 if(k != 3)
{
 printf("####################\n");
 }
 }
 return 0;
 } 



Measured memory_bytes: 2044
n,k=gets.chomp.split(" ").map{|s| s.to_i}
b=k
r=n-k

c=[]
for i in 0..n
  c[i]=[]
  for j in 0..n
    if i<j
      c[i][j]=0
    elsif j==1
      c[i][j]=i
    elsif j==0
      c[i][j]=1
    else
      c[i][j]=c[i-1][j]+c[i-1][j-1]
    end
  end
end

w=(10**9)+7
for i in 1..b
  puts (c[r+1][i]*c[b-1][i-1])%w
end

Measured memory_bytes: 390024
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

class BIT:
    def __init__(self, size):
        self.size = size
        self.tree = [0] * (size + 1)

    def add(self, index):
        while index <= self.size:
            self.tree[index] += 1
            index += index & (-index)

    def sum(self, index):
        ret = 0
        while index:
            ret += self.tree[index]
            index -= index & (-index)
        return ret

    def search(self, value):
        i = 0
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.tree[i + step] < value:
                i += step
                s += self.tree[i]
            step //= 2
        return i + 1

def sol():
    N = int(input())
    P = [None] + list(map(int, input().split()))

    ans = 0
    pToIndex = {p : i for i, p in enumerate(P[1:], 1)}
    tree = BIT(N)

    for p in range(1, N + 1)[:: -1]:
        c = pToIndex[p]
        left = tree.sum(c)
        tree.add(c)

        right = N - p - left

        a = tree.search(left - 1) if left >= 2 else 0
        b = tree.search(left) if left >= 1 else 0
        d = tree.search(left + 2) if right >= 1 else N + 1
        e = tree.search(left + 3) if right >= 2 else N + 1

        cnt = 0
        if b != 0:
            cnt += (b - a) * (d - c)
        if d != 0:
            cnt += (e - d) * (c - b)

        ans += cnt * p

    print(ans)

sol()

Measured memory_bytes: 67924
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<vector<int> ,vector<int> > P;
typedef pair<P,int> P2;
 
vector<int> g;
 
bool check(vector<int> a) {return a==g;}
 
int main() {
  for(int i=1; i<=4; i++) {
    for(int j=1; j<=8; j++) {
      if(j==8) g.push_back(0);
      else g.push_back(i*10+j);
    }
  }
 
  int T;
  cin >> T;
  while(T--) {
    vector<int> a(32);
    for(int i=0; i<4; i++) {
      for(int j=1; j<=7; j++) cin >> a[i*8+j];
    }
    vector<int> d(4);
    for(int i=0; i<32; i++) {
      if(i%8==0) continue;
      if(a[i]%10==1) {
    a[(a[i]/10-1)*8]=a[i];
    d[a[i]/10-1]=i;
    a[i]=0;
      }
    }
    set<vector<int> > se;
    se.insert(a);
    queue<P2> que;
    que.push(P2(P(a,d),0));
    int ans=-1;
    while(!que.empty()) {
      P2 p=que.front();que.pop();
      a=p.first.first;
      d=p.first.second;
      int cnt=p.second;
      if(check(a)) {
    ans=cnt;
    break;
      }
      for(int i=0; i<4; i++) {
    int x=a[d[i]-1]+1;
    if(x==0) continue;
    vector<int> a2=a,d2=d;
    for(int j=0; j<32; j++) {
      if(a2[j]==x) {
        a2[j]=0;
        a2[d[i]]=x;
        d2[i]=j;
        break;
      }
    }
    if(se.count(a2)) continue;
    se.insert(a2);
    que.push(P2(P(a2,d2),cnt+1));
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 15196
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

int main()
{

    int n, m;
    cin >> n >> m;
    vi a(m);
    vll dp(n + 10, 0);
    vector<bool> oks(n + 2, true);
    rep(i, 0, m)
    {
        cin >> a[i];
        oks[a[i]] = false;
    }
    dp[0] = 1;
    rep(i, 0, n)
    {
        if (oks[i])
        {
            dp[i + 1] += dp[i];
            dp[i + 1] %= MOD;
            dp[i + 2] += dp[i];
            dp[i + 2] %= MOD;
        }
    }
    cout << dp[n] << endl;
}


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

int main(int argc, char *argv[])
{
  for(;;){
    int n, l;
    cin >> n >> l;
    if(n == 0 && l == 0) break;
    vector<pair<pair<int,int>,int>> as;
    for(int i = 0; i < n; i++) {
      char c;
      int p;
      cin >> c >> p;
      as.push_back(make_pair(make_pair(p, c == 'R' ? 1 : -1), i));
    }
    int t = 0;
    int last = -1;
    for(;;){
      last = -1;
      // erase finished
      for(auto it = as.begin(); it != as.end(); ) {
        int p = (*it).first.first;
        if (p <= 0 || p >= l) {
          if(last == -1) last = (*it).second;
          it = as.erase(it);
        } else {
          it++;
        }
      }
      if(as.size()==0) break;
      t++;
      // move
      for(auto it = as.begin(); it != as.end(); it++) {
        (*it).first.first += (*it).first.second;
      }
      // sort
      sort(as.begin(), as.end());
      // reflect
      for(int i = 1; i < as.size(); i++) {
        if(as[i-1].first.first == as[i].first.first) {
          as[i-1].first.second = -as[i-1].first.second;
          as[i].first.second = -as[i].first.second;
        }
      }
    }
    cout << t << " " << (last+1) << endl;
  }
  return 0;
}



Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
#include <utility>
#include<map>
#include<functional>
#include<climits>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
ll dp(int k);
ll n, c[200000],memo[200000],same[200001],asd[200001];

int main() {
	fill(memo, memo + 200000, -1);
	fill(same, same + 200001, -1);
	fill(asd, asd + 200001, -1);

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		if (i != 0) {
			if (c[i] == c[i - 1]) {
				i--;
				n--;
				continue;
			}
		}
		if (same[c[i]] != -1) {
			asd[same[c[i]]] = i;
		}
		same[c[i]] = i;
	}

	cout << dp(0) << endl;
}

ll dp(int k) {
	if (memo[k] != -1)return memo[k];
	else if (k == n - 1)return 1;

	if (asd[k] == -1) {
		memo[k] = dp(k + 1);
	}
	else {
		memo[k] = (dp(k + 1) + dp(asd[k])) % mod;
	}
	return memo[k];
}

Measured memory_bytes: 12800
#define DEBUG 0
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 6/11/2019, 6:50:03 PM
 * Powered by Visual Studio Code
 */
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
typedef long long ll;
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}
void No()
{
  cout << "No" << endl;
  exit(0);
}
const int MAX_SIZE = 1000010;
class mint
{
public:
  static ll MOD;
  ll x;
  mint() : x(0) {}
  mint(ll x) : x(x % MOD) {}
  mint operator-() const { return mint(0) - *this; }
  mint &operator+=(const mint &a)
  {
    if ((x += a.x) >= MOD)
    {
      x -= MOD;
    }
    return *this;
  }
  mint &operator-=(const mint &a) { return *this += -a; }
  mint &operator*=(const mint &a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint &operator/=(const mint &a) { return (*this *= power(MOD - 2)); }
  mint operator+(const mint &a) const { return mint(*this) += a; }
  mint operator-(const mint &a) const { return mint(*this) -= a; }
  mint operator*(const mint &a) const { return mint(*this) *= a; }
  mint operator/(const mint &a) const { return mint(*this) /= a; }
  bool operator<(const mint &a) const { return x < a.x; }
  bool operator==(const mint &a) const { return x == a.x; }
  const mint power(ll N)
  {
    if (N == 0)
    {
      return 1;
    }
    else if (N % 2 == 1)
    {
      return *this * power(N - 1);
    }
    else
    {
      mint half = power(N / 2);
      return half * half;
    }
  }
};
ll mint::MOD = 1e9 + 7;
istream &operator>>(istream &stream, mint &a) { return stream >> a.x; }
ostream &operator<<(ostream &stream, const mint &a) { return stream << a.x; }
mint inv[MAX_SIZE];
mint fact[MAX_SIZE];
mint factinv[MAX_SIZE];
void init()
{
  inv[1] = 1;
  for (int i = 2; i < MAX_SIZE; i++)
  {
    inv[i] = (-inv[mint::MOD % i]) * (mint::MOD / i);
  }
  fact[0] = factinv[0] = 1;
  for (int i = 1; i < MAX_SIZE; i++)
  {
    fact[i] = mint(i) * fact[i - 1];
    factinv[i] = inv[i] * factinv[i - 1];
  }
}
mint choose(int n, int k)
{
  if (n >= 0 && k >= 0 && n - k >= 0)
  {
    return fact[n] * factinv[k] * factinv[n - k];
  }
  return 0;
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
// const double epsilon = 1e-10;
// const ll infty = 1000000000000000LL;
// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

int P, Q, R;

int main()
{
  cin >> P >> Q >> R;
  cout << P + Q + R - max(P, max(Q, R)) << endl;
}

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

#define mp make_pair
#define pb push_back

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int MAX_N = 200000;
int n;
int a[MAX_N];

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] -= i + 1;
  }

  sort(a, a+n);

  i64 s = 0;
  for (int i = 0; i < n; i++) {
    s += abs(a[i] - a[n/2]);
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Program {
    static Scanner sc = new Scanner();

    internal static void Main(string[] args) {
        var N = sc.nextInt();
        var a = sc.ArrayInt(N);

        long psum = 0;
        long msum = 0;
        long pcnt = 0;
        long mcnt = 0;
        for (int i = 0; i < N; i++) {
            psum += a[i];
            msum += a[i];
            if (i % 2 == 0) {
                if (psum <= 0) {
                    pcnt += 1 - psum;
                    psum = 1;
                }
                if (msum >= 0) {
                    mcnt += Math.Abs(-1 - msum);
                    msum = -1;
                }
            } else {
                if (psum >= 0) {
                    pcnt += Math.Abs(-1 - psum);
                    psum = -1;
                }
                if (msum <= 0) {
                    mcnt += 1 - msum;
                    msum = 1;
                }
            }
        }

        WriteLine(Math.Min(pcnt, mcnt));
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {

        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 26972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
public static void main(String[] args) throws IOException {

BufferedReader br =new BufferedReader (new InputStreamReader (System.in));

String line = br.readLine( );
String[] list = line.split(" ");

String x="D";

if(list[0]. equals(list[1])){
x ="H";
}
System. out. println(x);
}}

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

signed main()
{
    int k, ans, seven;
    cin >> k;
    
    if(k%2 == 0 || k%5 == 0){
        ans = -1;
    } else {
        seven = 7;
        ans = 1;
        
        seven = seven % k;
        while(seven != 0){
            ans ++;
            
            seven = seven * 10 + 7;
            seven = seven % k;
        }
    }
    
    cout << ans << endl;
    
    return (0);
}

Measured memory_bytes: 3628
#include<cstdio>
//#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int maxv = 10005;
const int inf = 1e9 + 7;
ll fpow(int x,int y){
	ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%inf;
    }
    return res;
}
int main(){
	int n;
	scanf("%d",&n);
	ll ans=fpow(10,n)-2*fpow(9,n)+fpow(8,n);
	ans%=inf;
	if(ans<0) ans+=inf;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1736
n = input()
k = int(input())

dp = [[[0,0] for i in range(len(n)+1)] for j in range(len(n)+1)]

# print(dp)
num_d = len(n)

dp[0][0][0] = 1

for i in range(len(n)):
    num = int(n[i])

    if num == 0:
        for j in range(num_d):
            dp[i+1][j+1][0] = dp[i][j][0]
            dp[i+1][j+1][1] += dp[i][j][1]

        for j in range(num_d+1):
            dp[i+1][j][1] += dp[i][j][1]*9

    else:
        for j in range(num_d):
            dp[i+1][j][0] = dp[i][j][0]

        for j in range(num_d+1):
            dp[i+1][j][1] += dp[i][j][0]*(num-1)
            dp[i+1][j][1] += dp[i][j][1]*9

        for j in range(num_d):
            dp[i+1][j+1][1] += dp[i][j][0] + dp[i][j][1]

# print(dp[-1])
if num_d < k:
    print(0)
else:
    print(sum(dp[-1][num_d-k]))

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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

const int mod=1000000007;
int N;
string S[1111];
vint G[1111];

int dfs(int v,int p){
    int ret=0;

    if(S[v][0]=='E'){
        ret=1;
        for(auto u:G[v]){
            if(u==p)continue;
            ret=ret*dfs(u,v)%mod;
        }

        if(S[v].size()==2)ret=(ret+1)%mod;
    }
    else if(S[v][0]=='A'){
        for(auto u:G[v])if(u!=p)ret=(ret+dfs(u,v))%mod;
        if(S[v].size()==2)ret=(ret+1)%mod;
    }
    else{
        ret=1;
        for(auto u:G[v])if(u!=p)ret=ret*(dfs(u,v)+1)%mod;
        if(S[v].size()==1)ret=(ret-1+mod)%mod;
    }
    return ret;
}

signed main(){
    cin>>N;
    rep(i,N)cin>>S[i];
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);G[b].pb(a);
    }

    cout<<dfs(0,-1)<<endl;
    return 0;
 }

Measured memory_bytes: 3244
from heapq  import heappush, heappop

N,M=map( int, raw_input().split() )
S="z"+raw_input()
num=[ [ 0 for i in range(2) ] for j in range(N+1) ] 

nl= [ [] for j in range(N+1) ] 

deleted=[ 0 for j in range(N+1) ] 

for i in range(M):
	a,b=map( int, raw_input().split() )
	if not b in nl[a]:
		nl[a].append(b)
		nl[b].append(a)
		if S[b]=="A":  num[a][0]+=1
		elif S[b]=="B":  num[a][1]+=1
		if S[a]=="A":  num[b][0]+=1
		elif S[a]=="B":  num[b][1]+=1

hq=[]

for i in range(1,N+1):
	if num[i][0]==0 or num[i][1]==0:
		heappush(hq,i)



while hq:
	x=heappop(hq)
	if deleted[x]==1: continue
	if num[x][0]==0 or num[x][1]==0:

		deleted[x]=1
		for u in nl[x]:
			if deleted[u]==0:
				if S[x]=="A": num[u][0]-=1						
				elif S[x]=="B": num[u][1]-=1
			
			if ( num[u][0]==0 or num[u][1]==0 ) and deleted[u]==0:
				heappush(hq,u)

				
if sum(deleted[1:])==N:
	print "No"
else:
	print "Yes"



Measured memory_bytes: 80156
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

int n,m;
string s;
vector<int> p;
vector<int> ans;

int win(int a,int b){
    int d=abs(a-b);
    if(s[d-1]=='1') return max(a,b);
    else return min(a,b);
}

void solve(int pos,int k,vector<int> v){
    int len=(int)v.size();
    if(v.size()==1){
        ans[pos]=v[0];
        return ;
    }
    vector<int> l,r;
    // l
    {
        rep(i,v.size()/2){
            l.push_back(win(v[2*i],v[2*i+1]));
        }
    }
    {
        rep(i,v.size()/2){
            r.push_back(win(v[(2*i+1)%len],v[(2*i+2)%len]));
        }
    }

    solve(pos,k+1,l);
    solve(pos+(1<<k),k+1,r);
}


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

    cin>>n;
    int m=(1<<n);
    cin>>s;
    p.resize(m);ans.resize(m);
    rep(i,m) cin>>p[i];
    solve(0,0,p);
    rep(i,m) cout<<ans[i]<<endl;
    return 0;
}



Measured memory_bytes: 9464
while True:
    n, l, r = map(int, input().split())
    if n == 0:
        break

    a = []
    for i in range(n):
        a.append(int(input()))
    a.append(1)
    cnt = 0
    for i in range(l, r+1):
        for j in range(n+1):
            if i % a[j] == 0:
                if j % 2 == 0:
                    cnt += 1
                break
    print(cnt)


Measured memory_bytes: 5600
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

typedef long long ll;
typedef complex<double> point;
typedef vector<int> vi;

template<class T>
inline int len(const T& t){
    return t.size();
}

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& val){
    os << "[ ";
    for(typename vector<T>::const_iterator it=val.begin();
        it != val.end();++it){
        os << *it << " ";
    }
    os << "]";
    return os;
}

struct Treasure{
    int value,weight;
    Treasure():
        value(0),weight(0) {};
    Treasure(int _value,int _weight)
        : value(_value),weight(_weight) {}
};

int main(){
    for(int loop_count=1;true;loop_count++){
        int W,N;
        cin >> W;
        if(W == 0) break;
        cin >> N;
        vector<Treasure> v(N);
        rep(i,N){
            char c;
            cin >> v[i].value >> c >> v[i].weight;
        }
        vi value(W+1);
        rep(n,N){
            vi tmp(W+1);
            rep(i,W+1){
                tmp[i] = max(tmp[i],value[i]);
                int in = i+v[n].weight;
                if(in <= W){
                    tmp[in] = max(tmp[in],value[i]+v[n].value);
                }
            }
            value.swap(tmp);
        }
        int retw=0;
        int retv=0;
        rep(i,len(value)){
            if(value[i] > retv){
                retv = value[i];
                retw = i;
            }
        }
        cout << "Case " << loop_count << ":" << endl;
        cout << retv << endl << retw << endl;
    }
    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

void solve(){
	int n,t,x;
	cin >> n >> x >> t;
	if(n % x == 0) cout << n / x * t << newl;
	else cout << (n / x + 1) * t << newl;

	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include <numeric>
#include<cmath>
using namespace std;
#define ll long long
typedef pair<int,int>P;
int main(void){
    int n,x;
    cin >> n>> x;
    int ans =1;
    for(int i=0;i<n;i++){
        int l;
        cin >> l;
        if(l<=x){
            x -= l;
            ans++;
        }else{
            x -= l;
        }
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef unsigned long ul;
const ul INF=1LL<<60;
const ul NN=1e5;
long N,t[NN],x[NN],y[NN],i,T,D;
inline void solve(){
  IN(N);
  INS3(i,N,t,x,y);
  if(t[0]<x[0]+y[0]){
    OUT("No");
    return;
  }
  FOR(i,1,N){
    T=t[i]-t[i-1];
    D=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
    if(T<D){
      OUT("No");
      return;
    }
    if((T-D)%2){
      OUT("No");
      return;
    }
    if(x[i]==x[i-1]&&y[i]==y[i-1]){
      OUT("No");
      return;
    }
  }
  OUT("Yes");
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 2560
require'prime'
l=[c=0]
Prime.each(1e6){|i|l<<c until l[i-1];l<<c+=1}
while(n=gets.to_i)>s=0
n.times{p,m=gets.split.map &:to_i;s+=(l[p+m]||l[-1])-l[p-m-1<0?0:p-m-1]-1}
p s
end

Measured memory_bytes: 16136
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;


const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++) {
    cin >> p[i];
  }
  int ans = 0;
  for(int i = 1; i < n - 1; i++) {
    if((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i + 1] < p[i] && p[i] < p[i - 1])) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int N;
  int p[50];
  int counter=0;

  scanf("%d\n",&N );
  for (int i = 0; i < N; i++) {
    scanf("%d",&p[i] );
  }

  for (int i = 0; i < N; i++) {
    if(p[i] != i+1){
      counter++;
    }
  }

  if(counter == 2 || counter == 0){
    printf("YES" );
  }else{
    printf("NO" );
  }
  return 0;

}


Measured memory_bytes: 128
using System;

public class Test
{
	public static void Main()
	{
		// your code goes here
		int N;
		
		N = int.Parse(Console.ReadLine());
		
		if(N/3==0)
		{
			Console.WriteLine(0);
		}
		else
		{
			Console.WriteLine(N/3);
		}
	}
}

Measured memory_bytes: 13140
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, A;
  cin >> N >> A;
  N = N - 500 * (N / 500);
  if (N <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;

struct node
{
    int key;
    node *parent,*left,*right;
    node():key(-1),parent(NULL),left(NULL),right(NULL) {}
};
node *root,*nil;

node* newnode()
{
    return new node();
}

void insert(int num)
{
    node* x=root;
    node* y=nil;
    node* z=newnode();
    z->key=num;
    while(x!=nil)
    {
        y=x;
        if(num>=x->key)
            x=x->right;
        else
            x=x->left;
    }
    if(y==nil) root=z;
    else
    {
        z->parent=y;
        if(num<y->key)
            y->left=z;
        else
            y->right=z;
    }
}

node* find(node* u,int num)
{
    while(u!=nil&&num!=u->key)
    {
        if(num< u->key) u=u->left;
        else u=u->right;
    }
    return u;
}

node* minele(node* u)
{
	while(u->left!=nil)
	  u=u->left;
	return u; 
}

node* nextpos(node* u)
{
	node* y=nil;
	if(u->right!=nil) y=minele(u->right);
	else 														//?¬¬????????\???????????????????????°?????¶???????°±???u?????????????????? 
	{
		y=u->parent;
		while(y!=nil&&y->right==u)
		{
			u=y;
			y=y->parent;
		}
	}
	return y;
}

void Delete(node* u)
{
	node* y;
	node* x;
	if(u->left==nil||u->right==nil) y=u;
	else y=nextpos(u);
	if(y->left!=nil) x=y->left;
	else x=y->right;
	
	if(x!=nil) x->parent=y->parent;
	
	if(y->parent==nil) root=x;
	else
	{
		if(y==y->parent->left) y->parent->left=x;
		else y->parent->right=x;
	}
	if(y!=u)
	  u->key=y->key;
	delete y;
}

void inorder(node* u)
{
    if(u->left!=nil) inorder(u->left);
    printf(" %d",u->key);
    if(u->right!=nil) inorder(u->right);
    return;
}

void preorder(node* u)
{
    printf(" %d",u->key);
    if(u->left!=nil) preorder(u->left);
    if(u->right!=nil) preorder(u->right);
    return;
}

int main()
{
    scanf("%d",&n);
    for(int i=1; i<=n; ++i)
    {
        char s[11];
        scanf("%s",s);
        if(s[0]=='i')
        {
            int x;
            scanf("%d",&x);
            insert(x);
        }
        else if(s[0]=='f')
        {
            int x;
            scanf("%d",&x);
            node* u=(find(root,x));
            if(u!=nil)
                printf("yes\n");
            else
                printf("no\n");
        }
        else if(s[0]=='d')
        {
        	int x;
        	scanf("%d",&x);
            Delete(find(root,x));
        }
        else if(s[0]=='p')
        {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}

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

int main(){
  int n,ans=0;
  cin>>n;
  REP(i,n) if((i>0&&i<1e1)||(i>1e2-1&&i<1e3)||(i>1e4-1&&i<1e5)) ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os
import math
import itertools

prices = []
amounts = []

for s in sys.stdin:
    price, amount = map(int, s.split(','))
    prices.append(price * amount)
    amounts.append(amount)

print(sum(prices))

mean = sum(amounts) / len(amounts) + 0.5
print(int(mean))

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

#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define vll vector<ll>
#define pll pair<ll , ll>
#define vpll vector<pair<ll, ll> >
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define N 100001
#define HOLE 1000000007

ll fn(ll x,ll rn[])
{
    if(rn[x]==x) return x;
    else return rn[x]=fn(rn[x],rn);
}

void un(ll x,ll y,ll rn[],ll sz[])
{
    x=fn(x,rn);
    y=fn(y,rn);
    if(x==y) return;
    if(sz[x]<sz[y]) swap(x,y);
    sz[x]+=sz[y];
    rn[y]=x;
    return;
}

ll power(ll x,ll y)
{
    ll res = 1; // Initialize result

    while (y > 0) {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x)%HOLE;

        // n must be even now
        y = y >> 1; // y = y/2
        x = (x * x)%HOLE; // Change x to x^2
    }
    return res;
}

vector <ll> adjl[N];
ll marked[N]={0};
vector <ll> order;

void dfs (ll x){

    if(marked[x])
        return;
    marked[x]=1;

    REP(i,0,adjl[x].size()){

    }

    return;
}

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

    ll q=1;
    //cin>>q;
    while(q--){

        string s;
        cin>>s;

        if(s[0]=='7' || s[1]=='7' || s[2]=='7'){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }




    }

return 0;
}


Measured memory_bytes: 5956
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2019-12-05 02:03:36
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>

using namespace std;

using int64 = long long;
#define debug(_) cerr << #_ << ": " << (_) << '\n'
template<class T> ostream& operator<<(ostream& os, vector<T>& _) { os << '{'; for (T& x : _) { os << x; if (&x != &_.back()) os << ','; } os << '}'; return os; }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

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

  int n; cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  if (is_sorted(a.begin(), a.end())) {
    cout << 0 << endl;
    return 0;
  }

  if (all_of(a.begin(), a.end(), [](int x){ return x >= 0; })) {
    cout << n - 1 << '\n';
    for (int i = 0; i < n - 1; ++i) {
      cout << i + 1 << " " << i + 2 << '\n';
    }
    return 0;
  }

  if (all_of(a.begin(), a.end(), [](int x){ return x <= 0; })) {
    cout << n - 1 << '\n';
    for (int i = n - 1; i >= 1; --i) {
      cout << i + 1 << " " << i << '\n';
    }
    return 0;
  }

  int mx = *max_element(a.begin(), a.end());
  int mn = *min_element(a.begin(), a.end());

  if (mx > abs(mn)) {
    int pos = distance(a.begin(), max_element(a.begin(), a.end()));
    cout << count_if(a.begin(), a.end(), [](int x){ return x < 0; }) + n - 1 << '\n';
    //debug(pos);
    for (int i = 0; i < n; ++i) {
      if (a[i] < 0) {
        a[i] += a[pos];
        cout << pos + 1 << " " << i + 1 << '\n';
      }
    }
    for (int i = 0; i < n - 1; ++i) {
      cout << i + 1 << " " << i + 2 << '\n';
    }
  } else {
    int pos = distance(a.begin(), min_element(a.begin(), a.end()));
    cout << count_if(a.begin(), a.end(), [](int x){ return x > 0; }) + n - 1 << '\n';
    //debug(pos);
    for (int i = 0; i < n; ++i) {
      if (a[i] > 0) {
        a[i] += a[pos];
        cout << pos + 1 << " " << i + 1 << '\n';
      }
    }
    for (int i = n - 1; i >= 1; --i) {
      cout << i + 1 << " " << i << '\n';
    }
  }

  return 0;
}

Measured memory_bytes: 256
///byYerko
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
using namespace std;
const int MXX = 2e3 + 7;
const int MXN = 1e6 + 7;
const int N = 1e9 + 7;

ll n, m;

int main() {
  cin >>n >>m;
  if((n * m) % 2 == 0) cout <<"Even";
  else cout <<"Odd";
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	vector<lint> dp(n);
	dp[0]=1000;
	for(int i=1;i<n;i++){
		dp[i]=dp[i-1];
		rep(j,i) if(a[j]<a[i]) dp[i]=max(dp[i],dp[j]%a[j]+dp[j]/a[j]*a[i]);
	}
	printf("%lld\n",dp[n-1]);

	return 0;
}


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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

int main() {
  cout << setprecision(18);
  u64 A, B, N;
  cin >> A >> B >> N;
  if (B > N)
    cout << A * N / B << endl;
  else {
    cout << A * (B - 1) / B << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
// #define endl " \n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define fr(i,f,t) for(ll i=(f);i<t;i++)
#define fb(i,f,t) for(ll i=(f);i>=t;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}

void cru(vector<vector<int>> &ans,vector<int> &chosen,vector<int> &arr,int index,int n,int start,int end){
	if(index==n){
		vector<int> temp(n,0);
		for(int i=0;i<n;i++){
			temp[i] = arr[chosen[i]];
		}
		ans.pb(temp);
		return;
	}
	for(int i=start;i<=end;i++){
		chosen[index] = i;
		cru(ans,chosen,arr,index+1,n,i,end);
	}
	return;
}

vector<vector<int>> cr(vector<int> &vec,int m,int n){
	vector<int> chosen(n+1,0);
	vector<vector<int>> ans;
	cru(ans,chosen,vec,0,n,0,m-1);
	return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,m,q;
    cin>>n>>m>>q;
    vector<int> a(q,0);
    vector<int> b(q,0);
    vector<int> c(q,0);
    vector<int> d(q,0);
    for(int i=0;i<q;i++){
    	cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    vector<int> arr(m,0);
    for(int i=0;i<m;i++){
    	arr[i] = i+1;
    }
    // cout<<"hello"<<endl;
    vector<vector<int>> data = cr(arr,m,n);
    // cout<<data.size()<<endl;
    // cout<<data[0].size()<<endl;
    ll mx = 0;
    for(int i=0;i<data.size();i++){
    	// print_array(data[i],n);
    	// cout<<"above is array------------"<<endl;
    	ll temp = 0;
    	for(int j=0;j<q;j++){
    		if((data[i][b[j]-1] - data[i][a[j]-1])==c[j]){
    			temp+=d[j];
    		}
    	}
    	if(temp>mx){
    		mx=temp;
    	}
    	// cout<<mx<<endl;
    }
    cout<<mx<<endl;

    return 0;
}

Measured memory_bytes: 9828
#include<iostream>
#include<unordered_map>

using namespace std;

int n, m;
string s[105], t[105];
unordered_map<string, int> M;

int main(){
  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> s[i];
    M[s[i]]++;
  }
  cin >> m;
  for(int i = 0; i < m; ++i){
    cin >> t[i];
    M[t[i]]--;
  }
  int ans = 0;
  for(int i = 0; i < n; ++i){
    ans = max(ans, M[s[i]]);
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define pr(n) cout << fixed << setprecision(n)
#define ci(n) cin >> n
#define ci2(n, o) cin >> n >> o
#define ci3(n, o, p) cin >> n >> o >> p
#define co(n) cout << n << endl

int main() {
  int N, A, B;
  ci3(N, A, B);
  co(min(N * A, B));
}  

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(x: "List[int]"):
    for i in range(len(x)):
        if x[i] == 0:
            print(i+1)
            return
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = [int(next(tokens)) for _ in range(5)]  # type: "List[int]"
    solve(x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61680
GU = 0
PA = 1
S = gets.scan(/./).map{|i|i == "g" ? GU : PA}
score = 0
count = [0, 0]
S.size.times{|n|
    if count[GU] == count[PA]
        score += GU - S[n]
        count[GU] += 1
        next
    end
    score += PA - S[n]
    count[PA] += 1
}
puts score


Measured memory_bytes: 10236
#include<iostream>
#include<string>
#include<list>
#include<vector>
using namespace std;


int main(){
	string s1,s2;
	while(true){
	cin>>s1;
	if(s1==".")break;
	cin>>s2;
	vector<string>p1,p2;//program 1,program2
	vector<string>t1,t2;//text1 text2

	bool flag=false;//f ???????????? !f ????????°??????
	int cnt=0;//?\???°????????????????????¶??°???????????°??????
	string tmpp,tmpt;

	for(int i=0;i<s1.size();i++){
		if(s1[i]=='"'){
			if((cnt+1)%2==0){//?????????????????????
				t1.push_back(tmpt);
				tmpt.clear();
			}

			else{//????????°???????????????
				p1.push_back(tmpp);
				tmpp.clear();
			}

			cnt++;
		}
		else{
			if((cnt+1)%2==0){//????????????
				tmpt.push_back(s1[i]);
			}
			else{//????????°??????
				tmpp.push_back(s1[i]);
			}
		}
	}
	if(s1[s1.size()-1]!='"')p1.push_back(tmpp);


 flag=false;//f ???????????? !f ????????°??????
	 cnt=0;//?\???°????????????????????¶??°???????????°??????
	tmpp.clear();tmpt.clear();
	for(int i=0;i<s2.size();i++){
		if(s2[i]=='"'){
			if((cnt+1)%2==0){//?????????????????????
				t2.push_back(tmpt);
				tmpt.clear();
			}

			else{//????????°???????????????
				p2.push_back(tmpp);
				tmpp.clear();
			}

			cnt++;
		}
		else{
			if((cnt+1)%2==0){//????????????
				tmpt.push_back(s2[i]);
			}
			else{//????????°??????
				tmpp.push_back(s2[i]);
			}
		}
	}

	if(s2[s2.size()-1]!='"')p2.push_back(tmpp);

	if(p1.size()!=p2.size()||t1.size()!=t2.size()){
		cout<<"DIFFERENT"<<endl;	
	}
	else{
	int wcnt=0;
	bool pflag=true;
	for(int i=0;i<p1.size();i++){
		if(p1[i]!=p2[i])pflag=false;
	}

	for(int i=0;i<t1.size();i++){
		if(t1[i]!=t2[i])wcnt++;
	}
	//for(int i=0;i<p1.size();i++)cout<<p1[i]<<" "<<p2[i]<<endl;
	//for(int i=0;i<t1.size();i++)cout<<t1[i]<<" "<<t2[i]<<endl;
	if(pflag&&wcnt==0)cout<<"IDENTICAL"<<endl;
	else if(pflag&&wcnt==1)cout<<"CLOSE"<<endl;
	else cout<<"DIFFERENT"<<endl;
	}
	}
	return 0;
}

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

using namespace std;

int main() {
	int a, b;
	char op;
	while (cin >> a >> op >> b && op != '?') {
		if (op == '+') {
			cout << a + b;
		} else if (op == '-') {
			cout << a - b;
		} else if (op == '*') {
			cout << a * b;
		} else {
			cout << a / b;
		}
		cout << '\n';
	}
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  string N;
  cin >> N;
  char tmp = N.back();
  // cout << tmp << endl;
  if (tmp == '2' || tmp == '4' || tmp == '5' || tmp == '7' || tmp == '9')
  {
    cout << "hon" << endl;
  }
  else if (tmp == '0' || tmp == '1' || tmp == '6' || tmp == '8')
  {
    cout << "pon" << endl;
  }
  else
  {
    cout << "bon" << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,m = LI()
    route = [None] + [[] for _ in range(n)]
    for _ in range(m):
        a,b = LI()
        route[a].append(b)
        route[b].append(a)

    explored = {1}
    queue = collections.deque([1])
    ans = [None for _ in range(n+1)]
    while len(queue)!=0:
        nxt = queue.popleft()
        for nbh in route[nxt]:
            if nbh not in explored:
                ans[nbh] = nxt
                queue.append(nbh)
                explored.add(nbh)
    print("Yes")
    print(*ans[2:],sep="\n")
        
main()            


Measured memory_bytes: 40972
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
typedef complex<double> Point;
const double EPS = 1.0e-9;
const double PI = acos(-1);
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int test; cin >> test;
    rep(casenum, test){
        Point a, b, c, m1, m2, d1, d2;
        cin >> a.real() >> a.imag() >> b.real() >> b.imag() >> c.real() >> c.imag();
        m1 = (a + b) / 2.0, m2 = (b + c) / 2.0;//????????¨???????????????, ????????¨????????????
        double s1 = arg(b - a) + PI / 2.0, s2 = arg(c - b) + PI / 2.0;//?????¨??´???????????????
        d1 = polar(1.0, s1), d2 = polar(1.0, s2);
        double k = (d1.real() * m1.imag() + d1.imag() * m2.real() - m1.real() * d1.imag() - d1.real() * m2.imag()) / (d1.real() * d2.imag() - d2.real() * d1.imag());
        double x = m2.real() + k * d2.real();
        double y = m2.imag() + k * d2.imag();
        double r = abs(Point(x, y) - a);
        printf("%.3lf %.3lf %.3lf\n", x, y, r);
    }
    return 0;
}

Measured memory_bytes: 1336
"""
掛け算は順序を入れ替えてもいいので、
√n + 1くらいまで探索
"""
import math
n = int(input())
r = []
def F(a,b):
    return max(len(str(a)),len(str(b)))
for i in range(1,int(math.sqrt(n))+1):
    if n%i == 0:
        r.append(F(i,n//i))
print(min(r))

Measured memory_bytes: 3060